Sunday, February 13, 2011

LINQ Tutorial : The from clause

I am currently preparing for exam 70-516. Reading Programming Microsoft LINQ in Microsoft .NET Framework 4 for it and loving it. Here is something new I learnt:

The syntax of from:
from rangeVariable in dataSource

Now if dataSource is a strongly typed collection (and these are the only ones I ever create) the rangeVariable will automatically be typed according to that.
e.g. if dataSource is IEnumerable , rangeVariable will be typed as T 

What I did not know
However if dataSource is ArrayList or any other untyped datasource you will need to specify the type in the syntax :
from T rangeVariable in untypedDataSource 


Cool eh.
Enjoy!

No comments:

Post a Comment