Lambad Expression Tree:
There are two ways to compile the lamabda Expression Tree:
If the first parameter of the expression is declared as ienumberable <t> type, the compiler will compile it into the middle of Il.CodeWhen the extension method inherits from iqueryable <t>, the compiler generates an Expression Tree.
VaR keyword, anonymous type, object initialization
The VaR keyword allows us to initialize variables without knowing the variable type, such:
VaR A = new {name = 'zhang san', sex = 'mal '};
But Initialization is required.
VaR A; // compilation Error
Object initialization:
The traditional method is to first create an object and then initialize the object, for example
Address = new address ();
Address. Address = "105 Elm Street ";
Address. City = "Atlanta ";
Address. State = "Ga ";
Address. postalcode = "30339 ";
However, when it is an anonymous type, the above method will not be able to be initialized
For the anonymous type, the following initialization method is available.
VaR A = new {name = 'bar '};
Expansion Method:
Necessity of expansion method: 1. It is impossible to create an instance method with the same (similar) operation for each object
2. Static methods cannot meet all the conditions.
The so-called expansion method is the static method of the static class called on the instance.
For example:
Namespace Test
{
Public static class person
{
Public static string speak (this string words)
{
Return "this person said:" + words;
}
}
}
This is an extension method, which can be used in all string instances.
Note: 1. Reference The namespace where the expansion method you write is located.
2. Extension methods cannot be written in generic classes.
Priority: If you declare a tostring () Extension Method in the person class above, it cannot be called in the string instance.
Because the instance method has a higher priority than the extension method.