-7

I have the following code, in which I want to verify if the the string called value matches an element contained in stringArray.

 string[] stringArray = { "text1", "text2", "text3", "text4" };

        string value = "text1";

        if ( /* ______________ */) // if value exists in stringArray
            Console.WriteLine("True");
        else
            Console.WriteLine("False");

Is there a method I could use to execute this?

user3648426
  • 227
  • 1
  • 4
  • 13
  • 1
    Your question may be voted down too due to amount of effort shown to search for possible solution. Please consider it for future questions. – Alexei Levenkov Jun 19 '14 at 23:09

2 Answers2

3

Enumerable.Contains will do the work:

using System.Linq;

if (stringArray.Contains("text1")) 
{
    Console.WriteLine("True");
}
Ohad
  • 168
  • 1
  • 11
0

I believe the following will work:

string[] stringArray = {"text 1", "text 2"};
string value = "text 1";
Console.WriteLine(stringArray.Any(str => str.Equals(value)) ? "True" : "False");
Aaron Medacco
  • 2,903
  • 2
  • 13
  • 12