Description (2018-4-6-20:31:03):
1. Last night to see three layers, after reading the final section of the first day, members of the modification and increase, feel the desire to die, decisive shut down the machine to sleep.
2. I had a half-day Harry Potter's original book epub download, the results have not found a layout can see, even more look at the sale of the genuine inside are the font size, then decided to look at Alice before looking at the other.
3.2 o'clock in the afternoon get up, start on the computer meditation, think that the form value how to get it, drag out two forms to, how to tinker all do not come out, in this more retwist, always think of 6:30, eat my mom roll noodles, and think one hours, estimated is 8 points, finally figured out, can realize the value of.
4. Before turning over the blog, about the delegation wrote not less than 10, including their own writing, copied from elsewhere. Most of the delegates are the basis of the use of the Commission is now on the internet has been marvellous, iffy its Xuan, almost its demon, how to say all have. However, there is no egg use, the article still understand, use the same time confused force.
5. So say, a thing you don't actually use it, you never know how to use it. All say the Commission is a hurdle, indeed is AH! You will not only see the people pretending to be forced to say what the Commission is actually very simple ah, in fact, is a pointer, as long as the understanding is very easy. Wait for the fart word.
6. It is because will not be commissioned, so I can not see the net, see the three layer, you could say will not be commissioned, you will not go down, just like there is a big river, you have to go to the other side, you have to entrust this bridge, you want to jump directly past is impossible!
7. This afternoon, I began to wonder, what is the connection between a delegate and a pointer, does the delegate save the address of a function? Because before in order to understand the principle of delegation, I learned a period of time data structure, so the old thought to lean on the pointer above, and then I went to check the information, the results on the road.
8. In the process of checking the information, it is said that the largest application of the Commission is in the design mode of the Observer mode, so to find the video, have to say Ah, C # really is not popular, search design mode, basically Java, finally find a talk about C #, talk about the design mode of the book, I have a copy in hand, but I don't have the part on the video yet. And I turned over the book, which is only the most basic use. I said the basis, is the most articles on the internet, MyDelegate mydel= SayHello; Mydel () This nutrient-free application.
9. Although the form passed a value of only a few lines of code, I thought for 6 hours. But when the program realized the moment, my joy is unspeakable, and even now are still in the joy, feel this day value. Even though the three-story event is more complicated, it's an introduction!
10. When I finally put a comment in the code, I actually improvised a story! The delegate is called a proxy, but I think the delegate is more like a spy!
11. Start Telling stories!
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_05 Form Pass value {//1. Defining the delegate (Mydel is like a Form2 spy, has sneaked into the Form1) Public Delegate voidMydel (stringstr); Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { //2. Binding delegate (Spy MDL got the remote control of this bomb)Mydel MDL =Changetxt; //Form2 is initialized by a construction method (at this point, the spy MDL can return to the Form2 base by Form2 's manned spacecraft)Form2 F2 =NewForm2 (TEXTBOX1.TEXT,MDL); F2. ShowDialog (); } //define the method, and in a few moments bind the delegate (someone buried a bomb in the Form1) Private voidChangetxt (stringstr) {TextBox1.Text=str; } }}
Form2.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_05 Form Pass value { Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); } //Form2 sent out a new spy. PrivateMydel MDL; PublicForm2 (stringStr,mydel MDL): This() { //The new spy, with the return of the spy handover, the new spy to get the remote control This. MDL =MDL; TextBox1.Text=str; } Private voidButton1_Click (Objectsender, EventArgs e) { //3. Invoke delegate (new spy Press the Remote control button, boom!!! )MDL (TextBox1.Text); } }}
Run Results reference: https://www.cnblogs.com/Jacklovely/p/7886612.html
Add:
1. Used to do this form value, has always thought that the delegate can only be written in Form2, but actually written in the Form1 can also, because the delegate is written under the namespace, the outside of the class, so as long as it is in this namespace, all places can be called to this delegate!
2. Form1.cs, you can not declare a delegate variable to bind the Changetxt method, you can directly put the Changetxt method into the Form2 of the constructor to pass through, but in order to understand, and match the plot, I added.
3. I think this example is very vivid, very day longitudinal wizards, I hope someone can read, haha ha!
C # Study notes (34)--Delegate pass value (recall version)