Instance Method And External Static Method C# with Example



Instance Method And External Static Method C# with Example

 using System;

namespace CSharpDelegate
{
	delegate void MyDelegate();
	
	public class UseDelegate
	{
		public void Display()
		{
			Console.WriteLine("I am Instance Method in UseDelegate Class being called via Delegate");
		}
		
		public static void Show()
		{
			Console.WriteLine("I am Static Method in UseDelegate Class being called via Delegate");
		}
	}
	
	class InstanceMethodAndExternalStaticMethod
	{
		static void Main()
		{
			MyDelegate callMethod = new MyDelegate(UseDelegate.Show);
			UseDelegate instance = new UseDelegate();
			
			callMethod += instance.Display;
			
			callMethod();
		}
	}	
}
 

0 Comment's

Comment Form

Submit Comment