Delete Callback From Method Invocation List C# with Example



Delete Callback From Method Invocation List C# with Example

 using System;

namespace CSharpDelegate
{
	delegate void MyDelegate();	//Delegate Declaration
	
	class DeleteCallbackFromMethodInvocationList
	{
		static void Main()
		{
			MyDelegate callMethod = new MyDelegate(Display);
			Console.WriteLine("After adding all methods in Invocation List");
			callMethod += Hello;
			callMethod = callMethod + Hi;
			callMethod += Bye;
			
			callMethod();
			
			Console.WriteLine("\nAfter deleting Hi() and Bye() methods from Invocation List");
			callMethod -= Hi;
			callMethod = callMethod - Bye;
			
			callMethod();
		}
		
		public static void Display()
		{
			Console.WriteLine("This is Display() Method.");
		}
		
		public static void Hello()
		{
			Console.WriteLine("This is Hello() Method.");
		}
		
		public static void Hi()
		{
			Console.WriteLine("This is Hi() Method.");
		}
		
		public static void Bye()
		{
			Console.WriteLine("This is Bye Method.");
		}		
	}	
}
 

0 Comment's

Comment Form

Submit Comment