Delegate--The value of 150525 between forms

Source: Internet
Author: User

Commission Summary

Summarize
As with Outputtime (), the compiler will put Outputtime (); compile into Outputtime.invoke ();
1 Defining delegate data types
2 Defining delegate variables
3 Determining whether a delegate type exists, using a delegate
if (outputtime! = null)
// {
As with Outputtime (), the compiler will put Outputtime (); compile into Outputtime.invoke ();
Outputtime.invoke ();
// }
File Write operation File.writealltext (@ "Aaa.text", System.DateTime.Now.ToString ("Yy-mm-dd hh-mm-ss"));

debugger, set breakpoints at the location you want to view, F10 next

General program to display time in two ways (console and write file)

Main program:classProgram {Static voidMain (string[] args) {Class1 T1=NewClass1 (); T1.outputtime=M1;                       T1.output1_time (); Class2 T2=NewClass2 (); T2.outputtime=M2;            T2.output1_time ();        Console.readkey (); }        Static voidM1 () {Console.WriteLine ("Current time: {0}", System.DateTime.Now.ToString ()); }        Static voidM2 () {File.writealltext (@"Aaa.text", System.DateTime.Now.ToString ("YY-MM-DD Hh-mm-ss")); }} class//define a delegate type     Public Delegate voidDele_time ();  Public classClass1 { PublicDele_time Outputtime;  Public voidOutput1_time () {Console.WriteLine ("--------------------------------------------------"); Console.WriteLine ("--------------------------------------------------"); if(outputtime!=NULL) {outputtime (); } Console.WriteLine ("--------------------------------------------------"); Console.WriteLine ("--------------------------------------------------"); }    }     Public classClass2 { PublicDele_time Outputtime;  Public voidOutput1_time () {Console.WriteLine ("--------------------------------------------------"); Console.WriteLine ("--------------------------------------------------"); if(Outputtime! =NULL)            {                //as with Outputtime (), the compiler will put Outputtime (); compile into Outputtime.invoke ( );Outputtime.invoke (); } Console.WriteLine ("--------------------------------------------------"); Console.WriteLine ("--------------------------------------------------"); }    }

Pass-through code between forms

1Defining delegate Types Public Delegate voidDele_chuanzhi (stringstr); Form1 codePrivate voidButton1_Click (Objectsender, EventArgs e) {Form2 F2=NewForm2 (); F2.            Show (); F2.chuanzhi=updatebtn; }  Private voidUPDATEBTN (stringstr) {TextBox1.Text=str; }form2 CodePrivate voidTextbox1_keyup (Objectsender, KeyEventArgs e) {            //This . Text = TextBox1.Text;            stringUinput = This. TextBox1.Text; if(Chuanzhi! =NULL) {Chuanzhi (uinput); }        }

Delegate--The value of 150525 between forms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.