| Start |
|---|
| Implicitly typed variables (var) The The types of the above variables are It is important to note that a |
Language Integrated Queries (LINQ) Example from wikipedia article on C# 3.0, LINQ sub-section (opens new window) Example 1 uses query syntax which was designed to look similar to SQL queries. Example from wikipedia article on C# 3.0, LINQ sub-section (opens new window) Example 2 uses method syntax to achieve the same outcome as example 1. It is important to note that, in C#, LINQ query syntax is syntactic sugar (opens new window) for LINQ method syntax. The compiler translates the queries into method calls at compile time. Some queries have to be expressed in method syntax. From MSDN (opens new window) - "For example, you must use a method call to express a query that retrieves the number of elements that match a specified condition." |
| Lambda expresions Lambda Expresions are an extension of anonymous methods (opens new window) that allow for implicitly typed parameters and return values. Their syntax is less verbose than anonymous methods and follows a functional programming style. The above code will output the sum of the squares of the numbers 1 through 10 to the console. The first lambda expression squares the numbers in the list. Since there is only 1 parameter parenthesis may be omitted. You can include parenthesis if you wish: or explicitly type the parameter but then parenthesis are required: The lambda body is an expression and has an implicit return. You can use a statement body if you want as well. This is useful for more complex lambdas. The select method returns a new IEnumerable with the computed values. The second lambda expression sums the numbers in list returned from the select method. Parentheses are required as there are multiple parameters. The types of the parameters are explicitly typed but this is not necessary. The below method is equivalent. As is this one: |
| Anonymous types Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler. You can make anonymous types by using the It's also possible to create an array of anonymous types. See code below: Or use it with LINQ queries: RemarksC# version 3.0 was released as part of .Net version 3.5. Many of the features added with this version were in support of LINQ (Language INtegrated Queries). List of added features:
|
Read Article
https://develop.horje.com/learn/1434/reference