string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" }; IEnumerable<string> query = fruits.TakeWhile(fruit => String.Compare("orange", fruit, true) != 0); foreach (string fruit in query) { Console.WriteLine(fruit); } /* This code produces the following output: apple banana mango */