Results 1 to 2 of 2

Thread: Delgates?????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    outerspace
    Posts
    126

    Delgates?????

    Im looking for further explanation into this concept.


    Ill be using the code below for my questions. It looks to me as the use of delegates allows you to declare many objects and latter when used call there methods?

    This is example 2 in the delgates tutorial in vs.net

    // compose.cs
    using System;

    delegate void MyDelegate(string s);

    class MyClass
    {
    public static void Hello(string s)
    {
    Console.WriteLine(" Hello, {0}!", s);
    }

    public static void Goodbye(string s)
    {
    Console.WriteLine(" Goodbye, {0}!", s);
    }

    public static void Main()
    {
    MyDelegate a, b, c, d;

    // Create the delegate object a that references
    // the method Hello:
    a = new MyDelegate(Hello);
    // Create the delegate object b that references
    // the method Goodbye:
    b = new MyDelegate(Goodbye);
    // The two delegates, a and b, are composed to form c,
    // which calls both methods in order:
    c = a + b;
    // Remove a from the composed delegate, leaving d,
    // which calls only the method Goodbye:
    d = c - a;

    Console.WriteLine("Invoking delegate a:");
    a("A");
    Console.WriteLine("Invoking delegate b:");
    b("B");
    Console.WriteLine("Invoking delegate c:");
    c("C");
    Console.WriteLine("Invoking delegate d:");
    d("D");
    }
    }
    "All those who wonder are not lost" -j.r.r tolkien

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I have an example of creating and using events with delegates at my site, it might help you:
    http://www.russellsplace.com/variant...%20Example.zip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width