Coding Convention

Aug 3, 2010 at 11:04 AM

// Proposed the following convention for code alignment.
class Program
{
	static void Main(string[] args)
	{
		int[] ints = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
		Sequence<int> nums = Sequence.Create(ints);
		Sequence<int> query = nums.Where(delegate(int i)
		{
			return i % 2 == 0;
		}).Select<int>(delegate(int i)
		{
			return i + i;
		});
		query.ForEach(Console.WriteLine);
		
		Person p1 = new Person("Peijuin");
		Person p2 = new Person("Pranalan");
		Person p3 = new Person("Elvin");
		Person[] personArray = new Person[] {p1, p1, p2, p3};
		
		Sequence<Person> people = Sequence.Create(personArray);
		Sequence<Person> selectedPeople =  people.Where(delegate(Person p)
		{
			return p.Name.StartsWith("P");
		});
		
		selectedPeople.ForEach(delegate(Person p)
		{
			Console.WriteLine(p.Name);
		});
	}
}

Aug 5, 2010 at 4:37 PM
eugenis wrote:

 

1.
Sequence<int> query = nums.Where(delegate(int i)
{
return i % 2 == 0;
}).Select<int>(delegate(int i)
{
return i + i;
});
2.
Sequence<Person> selectedPeople =  people.Where(delegate(Person p)
{
return p.Name.StartsWith("P");
});

selectedPeople.ForEach(delegate(Person p)
{
Console.WriteLine(p.Name);
});

 I don't really agree with this...  With lambda, we used to write like selectedPeople.Foreach( p => Console.WriteLine(p.Name) ); So, I think it makes sense to have only one line even we are using anonymous method as well.