Sign in | Join
Last post 11-05-2009 6:26 PM by Paul Linton. 4 replies.
Sort Posts: Oldest to newest Newest to oldest
//Sample 1 - Using Labmda Expression String str1 = "XXXwww.msdotnetsupport.blogspot.comXXX"; foreach (var item in str1.Where(x => x != 'X')) { Console.Write(item); } //Sample 2 - without Labmdas, and using ananymous method. String str2 = "XXXwww.msdotnetsupport.blogspot.comXXX"; foreach (var item in str2.Where<char>(delegate(char x) { return x != 'X'; })) { Console.Write(item); }//Sample 3 Now I do not want to use ananymouse delegate method as parameter to Where functionso can anybody can help me how to convert sample2 to sample3 without using anonymous function and map the parameter to below functionpublic static bool CharCheck(char x){ return x != 'X'}
foreach (var item in str2.Where<char>(CharCheck))
I think the previous poster meant
foreach (char letter in str2.Where<char>(x=>CharCheck(x)) )
(of course, your exact example could just be Console.Write(str2.Replace("X", string.Empty)) )
Paul Linton: I think the previous poster meant No, I actually tried that and it worked . As long as the method matches the necessary delegate, it works.
No, I actually tried that and it worked . As long as the method matches the necessary delegate, it works.
Sorry, my mistake.