The relationship between a type, a variable, and an instance.
Type "Variable" example
Types can create variables, entity classes can create instances, and instances can be stored in variables.
Second, the use of the Commission process:
1. Define the delegate (write a good signature);
2. Create a delegate variable;
3. Place the function (the same signature) in the delegate variable.
Event: A variable defined with a pre-defined delegate (Eventhandle) (receives two parameters).
The form has a delegate variable, and all we do is add the function to the variable.
Add a function to the form Load event
Public Partial class Form1:form { public Form1 () { InitializeComponent (); } Private void Form1_Load (object sender, EventArgs e) { }
An automatically generated expression
Go to definition to see the definition of the Load event
Iii. The origin of lambda expressions
Private voidButton1_Click (Objectsender, EventArgs e) { //Anonymous delegate func<int, Int> del//type "Variable" example//Func is an anonymous delegate type and is a type with no name//how to determine its signature: Several data types are required as parameters (previous specified parameter type, last specified return value type)//a delegate variable can be defined directly//anonymous function delegate (int a) {return A;}; //The difference from the normal function is that the function name is replaced with the delegate//The following expression, a variable that is defined by an anonymous delegate, refers to an anonymous function//The process of a=1 with int is the same truth//func<int, Int> del = delegate (int a) {return A;}; //MessageBox.Show (Del (5). ToString ()); //later found that the anonymous function must be placed in the delegate, the parameter type has been determined, so there is a more concise wording, the parameter type is also omitted//There's a lambda expression.func<int,int> del = a = = {returnA;}; MessageBox.Show (Del (6). ToString ()); }
C # Anonymous delegate, anonymous function, lambda expression