Answers for "simple delegate example in c#"

C#
1

how to create a delegate in c#

//the delegate can point to a void function and takes a string parameter
delegate void Del(string str);

public void hello(string Name)
{
 	Console.WriteLine("hello " + Name) ;
}
public static void main()
{
  //you need to declare the delegate type above and give it a function
  //that matches the delegate's funcion 
  Del HelloDelegate = new Del(hello);
  HelloDelegate("IC");
}
/// (output) -> "hello IC"
Posted by: Guest on January-04-2022

C# Answers by Framework

Browse Popular Code Answers by Language