کد زیر که با C#‎ 3.0 نوشتم حرفای زیادی واسه گفتن داره. شاید جالب باشه. سوالی بودم تو همین تاپیک در خدمتم.

using
System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace ConsoleApplication89
{
classProgram
{
staticvoid Main(string[] args)
{
//Collection Intialization
Collection<Person> PersonCollection = newCollection<Person>
{
//Type Initialization
newPerson(){ Name = "Name0", Age = 10 },
newPerson(){ Name = "Name1", Age = 11 },
newPerson(){ Name = "Name2", Age = 12 },
newPerson(){ Name = "Name4", Age = 14 },
newPerson(){ Name = "Name5", Age = 15 },
};
//LINQ
(from person in PersonCollection
where person.Age > 12 //Lambda Expression
select person).Perform(person => person.Write());
Console.ReadKey();
}
}
classPerson
{
//auto-implemented property
publicstring Name
{
get;
set;
}
publicint Age
{
get;
set;
}
publicoverridestring ToString()
{
returnstring.Format("Name = {0},\tAge = {1}", this.Name, this.Age);
}
}
staticclassExtensions
{
//Extension Method
internalstaticvoid Perform<TSource>(thisIEnumerable<TSource> sources, Action<TSource> actor)
{
foreach (var item in sources)
{
actor(item);
}
}
internalstaticvoid Write(thisobject obj)
{
Console.WriteLine(obj);
}
}
}