public delegate void del_call(int prntVal);//defining the delegate
public class ProduceRandom { del_call prDel;//local instance of delegate public ProduceRandom(del_call pp) { prDel = pp;//constructor to populate the local delegate } public void makeRandom() { Random rnd = new Random(); for(int i = 0; i<10; i++ ) { prDel( rnd.Next(0,10) );//generate 10 random numbers (from 0 to 10) } } }//end class ProduceRandom public class ConsumeRandom { public void printRandom(int rVal) { Console.WriteLine("Random = " + rVal); //delegate target, just print to console } }//end class ConsumeRandom public class xyz{ public static void Main(string[] args) { ConsumeRandom cr1 = new ConsumeRandom();//caveat - must instantiate consumer prior to producer ProduceRandom pr1 = new ProduceRandom(cr1.printRandom); pr1.makeRandom(); }//end Main }//end class
diggernicks 0 points 3.0 years ago
You surely live in a liberal hell hole
Off yourself