[{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","@id":"https:\/\/wiki.edu.vn\/en\/wiki12\/c-sharp-3-0-wikipedia\/#BlogPosting","mainEntityOfPage":"https:\/\/wiki.edu.vn\/en\/wiki12\/c-sharp-3-0-wikipedia\/","headline":"C Sharp 3.0 – Wikipedia","name":"C Sharp 3.0 – Wikipedia","description":"Version of the C# programming language The programming language C# version 3.0 was released on 19 November 2007 as part","datePublished":"2017-08-28","dateModified":"2017-08-28","author":{"@type":"Person","@id":"https:\/\/wiki.edu.vn\/en\/wiki12\/author\/lordneo\/#Person","name":"lordneo","url":"https:\/\/wiki.edu.vn\/en\/wiki12\/author\/lordneo\/","image":{"@type":"ImageObject","@id":"https:\/\/secure.gravatar.com\/avatar\/c9645c498c9701c88b89b8537773dd7c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c9645c498c9701c88b89b8537773dd7c?s=96&d=mm&r=g","height":96,"width":96}},"publisher":{"@type":"Organization","name":"Enzyklop\u00e4die","logo":{"@type":"ImageObject","@id":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","url":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","width":600,"height":60}},"image":{"@type":"ImageObject","@id":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","url":"https:\/\/wiki.edu.vn\/wiki4\/wp-content\/uploads\/2023\/08\/download.jpg","width":100,"height":100},"url":"https:\/\/wiki.edu.vn\/en\/wiki12\/c-sharp-3-0-wikipedia\/","wordCount":3350,"articleBody":"Version of the C# programming languageThe 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.[1] It is not currently standardized by any standards organisation.C# 3.0 features[edit]LINQ (language-integrated query)[edit]LINQ is a new Microsoft-specific extensible, general-purpose query language for many kinds of data sources\u2014including plain object collections, XML documents, databases, etc.\u2014which is tightly integrated with other C# language facilities. The syntax is different from, but borrows from SQL. An example:int[] array = { 1, 5, 2, 10, 7 };\/\/ Select squares of all odd numbers in the array sorted in descending orderIEnumerable query = from x in array where x % 2 == 1 orderby x descending select x * x;\/\/ Result: 49, 25, 1To 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.[2] Doing so makes more use of lambda functions, which are discussed below. The following is functionally identical to the example above.IEnumerable query = array.Where(x => x % 2 == 1) .OrderByDescending(x => x) .Select(x => x * x);\/\/ Result: 49, 25, 1 using 'array' as defined in previous exampleObject initializers[edit]Customer c = new Customer(); c.Name = \"John\";can be writtenCustomer c = new Customer { Name = \"John\" };Collection initializers[edit]MyList list = new MyList();list.Add(1);list.Add(2);can be written asMyList list = new MyList { 1, 2 };assuming that MyList implements System.Collections.IEnumerable and has a public Add method.[3]Local variable type inference[edit]Local variable type inference: var x = new Dictionary();is interchangeable with Dictionary x = new Dictionary();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[edit]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.var x = new { FirstName = \"John\", LastName = \"Doe\" };Anonymous types are reference types that derive directly from object. The compiler gives them a name although your application cannot access it. From the perspective of the common language runtime, an anonymous type is no different from any other reference type, except that it cannot be cast to any type except for object.If two or more anonymous types have the same number and type of properties in the same order, the compiler treats them as the same type and they share the same compiler-generated type information.[4]Lambda expressions[edit]Lambda expressions provide a concise way to write first-class anonymous function values. Compare the following C# 2.0 snippet:listOfFoo.Where(delegate(Foo x) { return x.Size > 10; });with this C# 3.0 equivalent:listOfFoo.Where(x => x.Size > 10);In the above examples, lambda expressions are merely shorthand syntax for anonymous delegates with type inference for parameters and return type. However, depending on the context they are used in, a C# compiler can also transform lambdas into ASTs that can then be processed at run-time. In the example above, if listOfFoo is not a plain in-memory collection, but a wrapper around a database table, it could use this technique to translate the body of the lambda into the equivalent SQL expression for optimized execution. Either way, the lambda expression itself looks exactly the same in the code, so the way it is used at run-time is transparent to the client.Expression trees[edit]Expressions, such as x "},{"@context":"http:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https:\/\/wiki.edu.vn\/en\/wiki12\/#breadcrumbitem","name":"Enzyklop\u00e4die"}},{"@type":"ListItem","position":2,"item":{"@id":"https:\/\/wiki.edu.vn\/en\/wiki12\/c-sharp-3-0-wikipedia\/#breadcrumbitem","name":"C Sharp 3.0 – Wikipedia"}}]}]