awkward syntax?

How awkward is the syntax for directly using a foreach statement directly over linq query results:


foreach(var xin from ein db.Employees where e.City == "Melbourne" selectnew{e.FirstName,e.LastName})
{
Console.WriteLine(x);
}


[595 byte] By [damienmorton] at [2008-2-15]
# 1
Is this a comment, or do you have a question?
JoshLindenmuth at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 2
a suggestion, yes
but Im not sure that it covers the full range of possible expressions


foreach(var e in db.Employees where e.City == "Melbourne")
{
Console.WriteLine(
new{e.FirstName,e.LastName});
}


damienmorton at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 3
Not everything need be written as a one-liner ;)

Kinda surprised you didn't use ForEach()...

KeithFarmer at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 4
This syntax would be possible using explicit dot notation. Do you think it is better?



foreach(var x in db.Employees.Where(e => e.City == "Melbourne"))
{
Console.WriteLine(x);
}

daveremy at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...

Visual Studio Orcas

Site Classified