Wednesday, October 6, 2010

C# and VB Extensions to Support LINQ

C# and VB Extensions to Support LINQ
LINQ is responsible for most new language extensions in VS 2008. Here ’ s a list of the LINQ - related
extensions to C# 3.0 and VB 9.0 with brief descriptions of their purpose:
Implicitly typed local variables infer the type of local variables from the expressions used to
initialize them.
Object initializers simplify the construction and initialization of objects of arbitrary types.
Array initializers extend object initializers to elements of arrays of arbitrary types. VB 9.0
doesn ’ t support array initializers.
Collection initializers (also called implicitly typed array initializers) extend the array initializer
style to infer the element type of the collection from the initializer. VB 9.0 doesn ’ t support
collection initializers.
Anonymous types enable creating tuple types with object initializers whose CLR type is
inferred by the compiler. C# anonymous types are immutable, but some VB anonymous types
are mutable.
Extension methods enable extending existing and constructed types with new methods.
Lambda expressions enable C# 2.0 ’ s anonymous methods to deliver better type inference and
allow conversions to expression trees and delegate types. VB 9.0 supports Lambda expressions
but doesn ’ t expose anonymous methods to programmers.
Standard Query Operators (SQOs. Also called Standard Sequence Operators ) filter, transform,
join, group, and aggregate collections of CLR types.
Query expressions group SQOs into a high - level query language that is similar to SQL and
related to XQuery.
Expression trees permit lambda expressions to be represented as data (expression trees) instead
of as code (delegates).
IQueryable < T > and IOrderedQueryable < T > interfaces, in conjunction with expression trees,
facilitate third - party LINQ implementations for other data domains and enable the compiling
of queries for improved performance. IQueryable < T > and IOrderedQueryable < T > types
enable composable queries by passing them as the data source of one or more additional
LINQ queries.LINQ also relies on these language features of C# 2.0 and VB 8.0:
Generic types let you specify the precise data type that a method, class, structure, or interface
acts upon. The primary benefits of generics are type safety and increased code reusability.
Anonymous methods (also called anonymous delegates) let you define a nameless method
that ’ s called by a delegate and access variables that would normally be out of scope. VB doesn ’ t
support anonymous methods directly.
Iterators , specifically the generic, type - safe IEnumerable < T > interface, in the System
.Collections.Generic namespace, which supports iterating over a generic collection in a
foreach or For Each ... Next loop.
Programs that don ’ t execute LINQ queries can take advantage of most new VS 2008 features. LINQ will
introduce the more abstract functional constructs, such as lambda expressions and expression trees, to
most .NET developers.

No comments:

Post a Comment