PASTE-IT!

Holding 570M in 38614 pastes. Meet us at #paste-it.net, OFTC!
Try our Mozilla Jetpack clipboard paster and our Chrome extension!
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var demo = new EventDemoClass();

            demo.GetName += demo_GetName;

            demo.GetNameFromConsoleApp();

            Console.Read();
        }

        static string demo_GetName(object sender, EventArgs e)
        {
            return "Seth Rowe";
        }
    }

    public delegate string GetNameEventHandler(object sender, EventArgs e);

    public class EventDemoClass
    {
        public event GetNameEventHandler GetName;

        public void GetNameFromConsoleApp()
        {
            Console.WriteLine(OnGetName(EventArgs.Empty));
        }

        protected virtual string OnGetName(EventArgs e)
        {
            if (GetName != null)
                return GetName(this, e);
            else
                return string.Empty;
        }
    }
}
}
Returning Values From An Event
by
Seth Rowe
pasted
542 day(s) ago
17:03 18-09-2008
in syntax