BrianMinister:
I am trying to figure out how to marshal a ling query result and even work with the resultset in general.
I have posted my questions as comments in the code below.
At the moment, I am at a dead standstill on linq until I can get past this.
namespace
LinqWoes
{
class Program
{
static void Main(string[] args)
{
NorthwindsDataContext ctx = new NorthwindsDataContext();
var ACustomers = from ac in ctx.Customers
where ac.ContactName.Substring(0, 1) == "A"
select ac;
// ACustomers.? I have lost strong typing by using var. Is thsi what I am supposed to use lamda expressions for?
// Should I use another type when declaring a return from a query?
DoSomethingWithA(ACustomers);
}
//How am I supposed to pass a linq query? This doesn't work.
bool DoSomethingWithA(var ac)
{
//Some code will go here.
}
}
}
Hi buddies,
As a matter of fact, C# is still a strong typed language (linq doesn't break the rule), so please don't mix up the keyword "var" in C# with the one in javascript.
In your case, var ACustomer will generate IL that is absolutely identical to the code: IEnumerable<Customer> ACustomer.
The var keyword just make your life easier and let the compiler to infer from the context what ACustomer really is.
Scott has wrote a blog to explain this in details, see Understanding the Var Keyword part of New "Orcas" Language Feature: Anonymous Types
Thanks