Underneath LINQ

    class Developer

    {

        public string Name { set; get; }

        public string Language { set; get; }

        public int Age { set; get; }

    }

 

    class Program

    {

        static void Main(string[] args)

        {

            var developers = new[] { new Developer{Name = "Marco", Language = "C#", Age=0},

                                    new Developer{Name="Paolo", Language="C#", Age=1},

                                    new Developer{Name="Redundant", Language="VB", Age=2}};

 

 

            var developerNames = from c in developers

                                where c.Language == "C#"

                                select c.Name;

 

 

            foreach(var name in developerNames)

                Trace.WriteLine(name);

 

            Func<Developer, bool> whereExpression = c => c.Language == "C#";

            Func<Developer, string> selectExpression = c => c.Name;

 

            IEnumerable<string> developerNames2 = developers.Where(whereExpression).Select(selectExpression);

 

            foreach (var name in developerNames2)

                Trace.WriteLine(name);

 

        }

    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s