Harish Kumar

How to find a specific string value inside a string array in c#

Published on 29 Nov 2020 · c#

To find a specific text or string inside an array of string you can use this simple trick with following code.


string[] stringArray = { "text1", "text2", "text3", "text4" }; 
string value = "text3"; 
int pos = Array.IndexOf(stringArray, value); 
if (pos > -1) 
{
    // the array contains the string and the pos variable
    // will have its position in the array
}