static void Main(string[] args) { AnotherClass ac = new AnotherClass(); DelegateExample de = new DelegateExample(); SampleDelegate sd = new SampleDelegate(ac.Method1); sd += de.DellMethod; sd.Invoke(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var del = new DelegateExample(); del.Delegate(); del.Action(); del.Function(); del.Predicate(); }
public static void Main(string[] args) { Person person = new Person(); person.Run(); Console.WriteLine("================================"); DelegateExample delegateExample = new DelegateExample(); delegateExample.AddNum(10, 5); AddNumDelegate adD = new AddNumDelegate(delegateExample.AddNum); SayHelloDelegate say = new SayHelloDelegate(DelegateExample.SayHello); string str = say("PCV"); str = DelegateExample.SayHello("PCV"); Console.WriteLine(str); Console.WriteLine("================================"); // ... // si apoi undeva in codul aplicatiei // ... // define some observers var observer1 = new IntegerCollectionChangeObserver("observer 1"); var observer2 = new IntegerCollectionChangeObserver("observer 2"); // define the observable collection ObservableIntegerCollection col = new ObservableIntegerCollection(); // attach both observers col.OnCollectionEvent += observer1.OnReceiveCollectionEvent; col.OnCollectionEvent += observer2.OnReceiveCollectionEvent; // make a change upon the collection and observe results col.Add(1); // Outputs: // observer 1 > ElementAdded just happend, affected element is: 1 // observer 2 > ElementAdded just happend, affected element is: 1 // detach second observer col.OnCollectionEvent -= observer2.OnReceiveCollectionEvent;; // make another change upon the collection and observe results col.Update(0, 2); // Outputs: // observer 1 > ElementUpdated just happend, affected element is: 2 Console.ReadKey(); }
static void Main(string[] args) { var delexample = new DelegateExample(); // Example: Delegate //delexample.LogRunningProc(CallBackMethod); // Example: Event delexample.Publisher += Subscriber1; delexample.Publisher += Subscriber2; // delexample.publisher = null; // not possible will throw exception. delexample.LogRunningProc(); Console.ReadLine(); }
static void Main(string[] args) { DelegateExample.Run(); DelegateParameterExample.Run(); MultiCastDelegateExample.Run(); }