I have a function that loops through an array of strings containing approximately 3 million lines of strings.  My problem is this loop is running too slowly and I want to know how to make it faster.string[] words = { Hello, world, !, My, name, is, Something, .};    List<MyClass> result = new List<MyClass>();    for (int i = 0; i < words.Length; i++)    {        if (words[i] == &&&)        { }        else if (words.Length > i + 2 && FileContains(words[i] +   + words[i + 1] +   + words[i + 2]))        {            result.Add(new MyClass(words[i] +   + words[i + 1] +   + words[i + 2]));            words[i + 1] = &&&;            words[i + 2] = &&&;        }        else if (words.Length > i + 1 && FileContains(words[i] +   + words[i + 1]))        {            result.Add(new MyClass(words[i] +   + words[i + 1]));            words[i + 1] = &&&;        }        else            result.Add(new MyClass(words[i], Parent));    }And my FileContains function which loops through the array of strings:public static bool FileContains(string Text){    foreach (string line in ARRAYOFWORDS)  // Approximately 3 million strings    {        if (Text.ToLower() == line.Substring(0, line.LastIndexOf('|')))        {            return true;        }    }    return false;}
Looping through an array of strings containing approximately 3 million elements
c#;performance;strings;multithreading
What is this for?  It looks like a string search function.  And you are storing the found results in an output.As such, I recommend not using an array at all.  You should make use of string.IndexOf, which uses Boyer Moyer Search Algorithm under the hood, very fast.Instead just make one BIG string with line breaks, for example...string stringToSearch = some line here\nanother line here\nand another line here\netc etc etc;int matchIndex = 0;while (matchIndex > -1){    matchIndex = stringToSearch.IndexOf(string to search for);    if (matchIndex > -1)    {        //use string functions to get matched word    }}Something like that for search a string, would be astronomically faster.You can load a file into a string in one move.  The TextReader object in the System.IO name space has a method called ReadToEnd which returns the entire file as a string with lines separated by new line characters \n.And, if you are dealing with a binary file, you can still search it string.IndexOf.  Just convert the binary file into a string with ASCIIEncoding.GetString(someByteArray), then convert your search for bytes to a string the same way.  Then search for the search bytes string in the converted file string.