c# check if word is in array of string code example

Example 1: how to know if an element is in an array c#

string[] names = "John", "Susan", "Sophie";
if (names.Contains("John") //Using Contains you can know if a specific value is on an array
    {
    Console.WriteLine("John is a name");
    }

Example 2: c# check if array contains value

public static bool Contains(Array a, object val)
    {
        return Array.IndexOf(a, val) != -1;
    }

Example 3: check if that inex exisits array c#

var array=new List<int>(1,2,3);
int count=5;
for(int i=0;i<count;i++){
	if(array.Count>i){  //this is way you can check wheater 
      	//do something   //index count equals to array count
	}
}