How to check if a value exists in an array (C#)

I am making a level generation algorithm. I have all my objects stored in an array. These objects are determined by numbers. I need to check whether the number “0” exists or not. How do I do this? Thanks

If you’re using an actual Array, you can use Array.Find() or Exists() to look for the matching member: Array.Find<T>(T[], Predicate<T>) Method (System) | Microsoft Learn or Array.Exists<T>(T[], Predicate<T>) Method (System) | Microsoft Learn

However, if you use a List instead, you can use List.Contains(), which has a bit easier syntax. List<T>.Contains(T) Method (System.Collections.Generic) | Microsoft Learn

you can check simple like the following :

C# Array full source code

        string stringToCheck = "GHI";
        string[] stringArray = { "ABC", "DEF", "GHI", "JKL" };
        foreach (string x in stringArray)
            if (x.Equals (stringToCheck))
                MessageBox.Show("Find the string ..." + x);


Its pretty simple, use this

string[] stringArray = { "text1", "text2", "text3", "text4" };
string value = "text3";
int pos = Array.IndexOf(stringArray, value);
if (pos > -1)
    return true;
    return false;