Callback With Return Value C# with Example



Callback With Return Value C# with Example

 using System;

namespace CSharpDelegate
{
	delegate string MyDelegate(string name);
	
	class DeleteCallbackWithReturnValue
	{
		static void Main()
		{
			MyDelegate callMethod = new MyDelegate(Display);
			callMethod += Hello;
			callMethod = callMethod + Hi;
			callMethod += Bye;
			
			Console.WriteLine(callMethod("Kuldeep"));
		}
		
		public static string Display(string name)
		{
			return string.Format("Name: " + name);
		}
		
		public static string Hello(string name)
		{
			return string.Format("Hello! " + name);
		}
		
		public static string Hi(string name)
		{
			return string.Format("Hi! " + name);
		}
		
		public static string Bye(string name)
		{
			return string.Format("Bye " + name);
		}
	}	
}
 

0 Comment's

Comment Form