Entrust Case 1

Source: Internet
Author: User

namespace Clslib//Common layer {public delegate void Writetimetodevdelegate ();//define Class}namespace Clslib//Common layer {public class Clas            S1 {public clslib.writetimetodevdelegate writetime;//delegate publicly void Dosth ()//Common method {            Console.WriteLine ("============================================");            Console.WriteLine ("============================================");            Console.WriteLine ("============================================"); Console.WriteLine ("============================================");
The other is the same part, but the code is not sure, the code in this method is determined by the future caller.
Because the code here is indeterminate, mutable. So we need to use a variable here. In the future, the caller will pass what code the variable is going to execute. Writetime (); Delegate variable Console.WriteLine ("============================================"); Console.WriteLine ("============================================"); Console.WriteLine ("============================================"); Console.WriteLine ("============================================"); } }}

T1 Call

Namespace T1  //t1 Project {    class program      {        static void Main (string[] args)        {            Clslib.class1 c1 = new Clslib.class1 (); Real class public class            C1. Writetime = M1; Give the M1 method to the entrusted            C1. Dosth ();             Console.readkey ();        }        static void M1 ()        {            Console.WriteLine ("Current time: {0}", System.DateTime.Now.ToString ("Yyyy-mm-dd hh:mm:ss");        }    }}

T2 Project Invocation

Namespace T2//t2 Project {    class program    {        static void Main (string[] args)        {            Clslib.class1 c1 = new Clslib . Class1 ();            C1. Writetime = M1;            C1. Dosth ();            Console.readkey ();        }        static void M1 ()        {            file.writealltext (@ "Time.txt", System.DateTime.Now.ToString ("Yyyy-mm-dd hh:mm:ss"));            Console.WriteLine ("Time has been written to file");}}}    

Entrust Case 1

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.