I like my linq like this:
string str = "A quick brown fox"; char[] chars = { 'A', 'B', 'C', 'D', 'E', 'F' }; var query = from c in str.Substring(0, 1) join c1 in chars on c equals c1 select c;
This will give you all the characters in the list corresponding to the first character of the string. A slight modification, and you can even get the character index in the list of characters you are looking for, in this case index 0.
here is this code:
string str = "A quick brown fox"; char[] chars = { 'Z', 'X', 'A', 'B', 'C', 'D', 'E', 'F' }; var query = from c in str.Substring(0, 1) join c1 in chars on c equals c1 select new { Character = c, Index = chars.ToList().IndexOf(c) }; var found = query.ToArray();
source share