Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Event .net guidelines
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { // Derive a class from EventArgs. class MyEventArgs : EventArgs { public int EventNum; } // Declare a delegate type for an event. delegate void MyEventHandler(object sender, MyEventArgs e); // Declare a class that contains an event. class MyEvent { static int count = 0; public event MyEventHandler SomeEvent; // This raises SomeEvent. public void OnSomeEvent() { MyEventArgs arg = new MyEventArgs(); if(SomeEvent != null) { arg.EventNum = count++; SomeEvent(this, arg); } } } class X { public void Handler(object sender, MyEventArgs e) { Console.WriteLine("Event " + e.EventNum + " received by an X object."); Console.WriteLine("Source is " + sender); Console.WriteLine(); } } class Y { public void Handler(object sender, MyEventArgs e) { Console.WriteLine("Event " + e.EventNum + " received by a Y object."); Console.WriteLine("Source is " + sender); Console.WriteLine(); } } public class Program { public static void Main(string[] args) { X ob1 = new X(); Y ob2 = new Y(); MyEvent evt = new MyEvent(); // Add Handler() to the event list. evt.SomeEvent += ob1.Handler; evt.SomeEvent += ob2.Handler; // Raise the event. evt.OnSomeEvent(); evt.OnSomeEvent(); } } }
run
|
edit
|
history
|
help
0
Ok
Punnet Square Generator
Generic class and method example in C#
checker
ray's 2nd test
Why Linqdb is cool if you are a Csharper
Only unique chars into string?
test
de Decimal a Binario
Nullable type - Value Exception - Solution