There is a code in C #, I need to remake if ((product.Contains ("mysql: mysql")) || ... so that the lines are taken from the list.

public List<string> GetIDDesiredDB(List<EntryType> entries) { List<string> IDs = new List<string>(); string id = ""; //List<string> products = GetProductsList(); foreach (EntryType entry in entries) if (entry.VulnerableSoftwareList != null) foreach (string product in entry.VulnerableSoftwareList.Products) if ((product.Contains("mysql:mysql")) || (product.Contains("microsoft:sql_server")) || (product.Contains("oracle:mysql")) || (product.Contains("oracle:database"))) if (id != entry.id) { IDs.Add(entry.id); id = entry.id; } return IDs; } 

I do this, but I don’t go into if:

 var products = GetProductsList(); // [ "mysql:mysql", "microsoft:sql_server", "oracle:mysql", "oracle:database" ] foreach (string product in products) if(entry.VulnerableSoftwareList.Products.Contains(product)) 
  • Maybe your products an empty list? - VladD
  • we, telepaths, now guess what lies behind the var, var, var... - Igor
  • @Igor: The question is not in the types, but in the contents of the list, I think. What will give us the fact that entry is of type Entry , in which there is an open field / property VulnerableSoftwareList ? - VladD
  • one
    Does the Contains () method use lambda expressions? Or is VulnerableSoftwareList.Products just a string[] ? - isnullxbh
  • @VladD the list is not empty - Viktor Bylbas

1 answer 1

  public List<string> GetIDDesiredDB(List<EntryType> entries) { List<string> IDs = new List<string>(); string id = ""; List<string> products = GetProductsList(); foreach (EntryType entry in entries) if (entry.VulnerableSoftwareList != null) foreach (string product in entry.VulnerableSoftwareList.Products) foreach (string prod in products) if (product.Contains(prod)) { if (id != entry.id) { IDs.Add(entry.id); id = entry.id; } break; } return IDs; } 

Thank you all, did so. Earned

  • @FoggyFinder, yes, that's right - Viktor Bylbas
  • one
    "Earned" - but did you understand why it worked? - Igor
  • @FoggyFinder so that id is not duplicated - Viktor Bylbas
  • @Igor not really - Viktor Bylbas
  • @FoggyFinder I need to get the id of the entry that contains at least one item in the entry.VulnerableSoftwareList.Products - Viktor Bylbas