Assignment Compatibility With Delegates C# with Example



Assignment Compatibility With Delegates C# with Example

 	using System;

	namespace CSharpGenerics
	{	
		delegate T MyDelegate();			//Generic Delegate
		class BaseClass
		{
			public void Display()
			{
				Console.WriteLine("BaseClass Display Method.");
			}
		}
		
		class DerivedClass : BaseClass{}
		
		class Program
		{

			static DerivedClass CreateDerivedObject()	//Delegate Matching Method
			{
				return new DerivedClass();
			}
			
			static void Main(string[] args) 
			{
				MyDelegate derivedObjectCreator = CreateDerivedObject; //Create Delegate Object
				MyDelegate baseObjectCreator = derivedObjectCreator; 	//Assign Delegate Object
				
				baseObjectCreator().Display();
				
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment