*** Welcome to piglix ***

C Sharp 3.0


The programming language C# version 3.0 was released on 19 November 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query (LINQ) pattern to the Common Language Runtime. It is not currently standardized by any standards organisation.

LINQ is a new Microsoft-specific extensible, general-purpose query language for many kinds of data sources—including plain object collections, XML documents, databases, etc.—which is tightly integrated with other C# language facilities. The syntax is different from, but borrows from SQL. An example:

To implement LINQ, a large range of new methods were added to many collections via the System.Linq.Enumerable class. LINQ expressions are translated to use these functions before compilation. As an alternative, which is sometimes more powerful or direct, these functions may be accessed directly. Doing so makes more use of lambda functions, which are discussed below. The following is functionally identical to the example above.

can be written

can be written as

assuming that MyList implements System.Collections.IEnumerable and has a public Add method.

Local variable type inference:

is interchangeable with

This feature is not just a convenient syntactic sugar for shorter local variable declarations, but it is also required for the declaration of variables of anonymous types. The contextual keyword "var", however, may only appear within a local variable declaration.

Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to first explicitly define a type. The type name is generated by the compiler and is not available at the source code level. The type of the properties is inferred by the compiler.


...
Wikipedia

...