Projection Linq : Projection « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

    public class Person
    {
        public int Age { get; set; }
        public string Name { get; set; }

        List<Person> friends = new List<Person>();
        public List<Person> Friends
        {
            get { return friends; }
        }

        public Person()
        {
        }

        public Person(string name)
        {
            Name = name;
        }
    }
    class Projection
    {
        static void Main()
        {
            List<Person> family = new List<Person>                 
            {
                new Person {Name="H", Age=31},
                new Person {Name="J", Age=31},
                new Person {Name="T", Age=4},
                new Person {Name="W", Age=1}
            };

            var converted = family.ConvertAll(delegate(Person person)
                { return new { person.Name, IsAdult = (person.Age >= 18) }; }
            );

            foreach (var person in converted)
            {
                Console.WriteLine("{0} is an adult? {1}",
                                  person.Name, person.IsAdult);
            }
        }
    }








22.57.Projection
22.57.1.Projection Operators: do calculation in select statement
22.57.2.Projection Linq
22.57.3.Projection Creates New Objects