static void Main(string[] args) { A theA = new A(); ComplicatedDel complicatedDel = theA.f; TheDelegate resultFunctrion = theA.f(100); TheDelegate resultFunction2 = complicatedDel(900); Console.WriteLine("Tests:"); Console.WriteLine(resultFunctrion(100)); Console.WriteLine(resultFunctrion(112)); Console.WriteLine(); Console.WriteLine("Assigning null to theA"); theA = null; // The Scope feature // Scope is a special class that is created by the C# (not by the .NET platform) // that "exports" all of the local parameters of the A class that are used by // the lambda function in the f method. Console.WriteLine(); try { Console.WriteLine(theA.f(3)); } catch (NullReferenceException nullRef) { Console.WriteLine("Yes, an exception was thrown. Instance theA already \"doesn't exist\"."); Console.Write("The exception message: "); Console.WriteLine(nullRef.Message); } Console.WriteLine(); Console.WriteLine("But the delegate is still functioning properly. It is important to notice that the method in the delegate uses local parameters of theA which alredy doesn't exist."); Console.WriteLine("The result:"); Console.WriteLine(resultFunctrion(113)); Console.WriteLine("Testing Complicated delegate"); Console.WriteLine(resultFunction2(100)); }
void Test4() { var cls = new Test4ClassB(); var dlg = new TheDelegate(((Test4ClassA)cls).TheMethod); dlg(1, null); }
public TheDelegate f(int c) { int d = 5; TheDelegate del = (int x) => x + a + b + c + d; return(del); }
public void CrmParticipantsDidFailWithError(UPCRMRecordParticipants recordParticipants, Exception error) { ControllerState = GroupModelControllerState.Error; Error = error; Group = null; if (signalFinished) { TheDelegate.GroupModelControllerFinished(this); } }
// Method takes the array and whatever method is passed into the method. static IEnumerable<int> GetNumbers(IEnumerable<int> numbers, TheDelegate gauntlet) { // Iterate the array foreach (var x in numbers) { // Use the passed in method to run the value. if (gauntlet(x)) { // return the value if it meets the passed in methods condition. yield return x; } } }
void Test1() { var dlg = new TheDelegate(MyStaticDelegate); dlg(1, new Exception("STATIC")); var inst = new TestDelegate(); dlg = new TheDelegate(inst.MyVirtualDelegate); dlg(2, new Exception("VIRTUAL")); var inst2 = new MyDelegateClass <long, object, bool>(); dlg = new TheDelegate(inst2.GenericDelegate); bool b3 = dlg(3, new Exception("INSTANCE GENERIC")); dlg = new TheDelegate(StaticGenericDelegate <long, object>); dlg(4, new Exception("STATIC GENERIC")); dlg = new TheDelegate(this.InstanceGenericDelegate <long, object>); dlg(5, new Exception("INSTANCE GENERIC")); }
public static void Parse(TheDelegate pDelegate, CodeBuilder pBuilder) { }
public static void Parse(TheDelegate pDelegate, CodeBuilder pBuilder) { }
//Methods public void InitDelegate() { //Instatiation of the deleagate (did not allow to pass non-static method if located on class level) theDelegte = new TheDelegate(StatusLabelChange); }
//Methods public void InitDelegate() { //Instatiation of the deleagate (did not allow to pass non-static method if located on class level) theDelegte = new TheDelegate(StatusLabelChange); }