To enable LINQ to be seamless and integrated with the C # language, Microsoft has added new features to c#3.0, which focuses on enhancing LINQ-related.
1, the VAR keyword, collection initialization, and anonymous types
2. LAMBDA expression
3. Partial (Partial) method
4. Extension method
5. Expression tree
1, the VAR keyword, collection initialization, and anonymous types
Var:
You can give local variables the inference of "type" var instead of an explicit type. The VAR keyword instructs the compiler to infer the type of the variable based on an expression to the right of the initialization statement. The inferred type can be a built-in type, an anonymous type, a user-defined type, a type defined in the. NET Framework class Library, or any expression. var simply represents the most appropriate type to be determined and assigned by the compiler. is different from the concept of Var in JavaScript. For example: var i = 5; After compiling i is an integral type, and int i=5; In many cases, Var is optional, and it only provides grammatical convenience.
Take a look at the following examples:
var i = 5;//int
var j = 23.56;//double
var k = "C Sharp";//string
var x;// 错误
var y = null;//错误
var z = { 1, 2, 3 };//错误
Object and Collection initializer:
Class User
{
public int ID {get; set;}
public string
Name {get; set;}
public int Age {get; set;}
}
User user = new user
();
User. Id = 1;
User. Name = "LFM";
User. age = 22;