Replace List<T>.Where() with your own "Where" to understand Func<T>

by sunil ravulapalli /1. March 2014 06:25 /c# /Comments (0)
class Program
{
	static void Main(string[] args)
	{
		List<string> names = new List<string> {
											"mickey",
											"donald",
											"goofy",												
									};

		var outnames = names.Finder(x => x == "donald");

		foreach (var name in outnames) 
		{
			Console.WriteLine(name);
		}
		Console.ReadLine();            
	}        
}

public static class MyExtentions
{
	public static IEnumerable<string> Finder(this IEnumerable<string> strings, Func<string, bool> predicate)
	{
		foreach (var str in strings)
		{
			if (predicate(str) == true)
				yield return str;
		}
	}
}
blog comments powered by Disqus