c# - How to check dictionary if string value exist for conditional comparison -


if want use dictionary given values conditional comparison in if-statement pass implementation avoid if-statement listing of values , dictionary. how check dictionary, contains 400 strings, if string value exist:

    dictionary<int, string> set1 = new dictionary<int, string>()                               {{ 1, "string1" }, { 2, "string2" } ... }; // 400 values 

so seems way wrong:

    string str = "string1";      if (set1.containskey(str) == true)     {          console.writeline("contains");     }     else     {          console.writeline("does not contains");     } 

to result further condition

containsvalue(value);

string str = "string1";  if (set1.containsvalue(str) == true) {      console.writeline("contains"); } else {      console.writeline("does not contains"); } 

or linq:

using system.linq; ... string str = "string1";  if (set1.values.any(x => x == str)) {      console.writeline("contains"); } else {      console.writeline("does not contains"); } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -