Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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"
 
PREVIOUS NEXT
Tagged: #create #delegate
ADD COMMENT
Topic
Name
5+1 =