Using LINQ With Strings
LINQ can be used to perform query operations on objects which implement the IEnumerable<T>. Since the String class implements the IEnumerable<char> interface we can perform various string operations using LINQ. In the below example I have used LINQ to extract the common characters in two strings.
Note: For some weired reason Visual Studio doesn't show the LINQ extension methods in the intellisense for string objects.
string str1 = "abc"; string str2 = "bcd"; Funcmatch = (s,c) => s.Contains(c); var chars = from c in str1 where match(str2, c) select c; foreach (var c in chars) { Console.WriteLine(c); } Console.Read();
Here is the Output: