Again I thoroughly enjoyed speaking to Carl (he is a great host) about Ruby
like features of .NET.
I hope you enjoyed the show as much as I did being on it.
Fifteen minutes after the show (now that's true passion), Milan writes:
Hi
Dr. Venkat
I was so exited with your very last show on dnrTV, so I've tried to generalize FindAll
method and I'm sending you my code, made 15 minutes after I've seen the show. I don't
know if you
are interested in it
and what will you do about
it, but I've just had to share my excitement with someone (I've sent it to Carl also.
He's such a good host). So here it goes:
using System;
using System.Collections.Generic;
namespace LambdaGenericsExtenders_Example
{
class Program
{
static void Main(string[]
args)
{
var list = new int[]
{ 5, 3, 6, 4, 37, 2, 4 };
var sList = new string[]
{ "This", "is", "so", "cool", "man", "!" };
foreach (var
i in sList.FindAll(elem
=> !elem.Contains("is")
&& elem != "!"))
Console.WriteLine(i);
Console.WriteLine("=================");
foreach (var
i in list.FindAll(elem
=> elem > 3))
Console.WriteLine(i);
Console.ReadKey();
}
}
public delegate bool Evaluator<T>(T
val);
public static class Extender
{
public static IEnumerable<T>
FindAll<T>(this T[]
array, Evaluator<T> eval)
{
foreach (var
val in array)
if (eval(val))
yield return val;
}
}
}
---
Sorry if I've
disturbed you, but if you continue to
have that Great shows, it'll happen again :-)
Thank you for the threat Milan! You're a great inspiration for a lot of us.