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. Append the reference function (same signature) to the delegate variable.
Iii. The origin of lambda expressions
private void Button1_Click (object sender, EventArgs e) { //anonymous delegate func<int, int> del //type ' variable ' instance //func is an anonymous delegate type, which is an unnamed type //How to determine its signature: requires several data types as parameters (preceding parameter type, last specified return value type) //can directly define a delegate variable // anonymous function delegate (int a) {return A;}; The difference from the normal function is that the function name is replaced with the delegate //following expression, which is a variable defined by the anonymous delegate del refers to the process of an anonymous function //and int a=1, is the same //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 omitted //There is a lambda expression func<int, int> del = a + = { return A; }; MessageBox.Show (Del (6). ToString ()); }
Tips:
Define an anonymous delegate variable, like we're sure to build a gun, but the gun doesn't work, because it's just the stage of functional design , the function of the gun is: Give it a bullet (parameter), we get a high-speed flying bullet (return value);
Assigning a lambda expression to this delegate variable is like giving the gun a process of internal construction such as a barrel, a trigger, and then the gun can work.
Iv. events in the WinForm form
WinForm Form event: A variable defined with a predefined delegate (Eventhandle) (receives two parameters).
The form has a delegate variable, and all we do is add the function to the variable.
1.
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
C # Anonymous delegate, anonymous function, lambda expression