Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Delegates | Interactive GUI
Advanced C# with .NET

DelegatesDelegates

According to some definitions of signature, the return type of a method is not included in the signature of a method for-example in context of method overloading we don't include the return type of the method when referring to the method's signature however in context of delegates, the term signature refers to both the return type and the parameter list of the method.

Important Points:

  • Delegates are types that can reference methods of a certain kind of signature;
  • Delegates allow us to pass methods as arguments;
  • The syntax of a creating a new delegate type is as follows: delegate <return type> <type name> (parameter1, parameter2, …);;
  • We can create a variable using a delegate type and assign it a method reference using the following syntax: DelegateTypeName variableName = methodName;;
  • More methods can be added to a delegate instance using the += operator;
  • Methods can be removed from a delegate instance using the -+ operator;
  • In case there are multiple methods in a delegate instance that return a value, the value of the last executed method is returned;
1. What is a delegate in C#?
2. Which of the following is a correct syntax to declare a delegate named "MyDelegate" that takes an integer parameter and returns void?

What is a delegate in C#?

Виберіть правильну відповідь

question-icon

Which of the following is a correct syntax to declare a delegate named "MyDelegate" that takes an integer parameter and returns void?

Виберіть кілька правильних відповідей

Все було зрозуміло?

Секція 2. Розділ 1
course content

Зміст курсу

Advanced C# with .NET

DelegatesDelegates

According to some definitions of signature, the return type of a method is not included in the signature of a method for-example in context of method overloading we don't include the return type of the method when referring to the method's signature however in context of delegates, the term signature refers to both the return type and the parameter list of the method.

Important Points:

  • Delegates are types that can reference methods of a certain kind of signature;
  • Delegates allow us to pass methods as arguments;
  • The syntax of a creating a new delegate type is as follows: delegate <return type> <type name> (parameter1, parameter2, …);;
  • We can create a variable using a delegate type and assign it a method reference using the following syntax: DelegateTypeName variableName = methodName;;
  • More methods can be added to a delegate instance using the += operator;
  • Methods can be removed from a delegate instance using the -+ operator;
  • In case there are multiple methods in a delegate instance that return a value, the value of the last executed method is returned;
1. What is a delegate in C#?
2. Which of the following is a correct syntax to declare a delegate named "MyDelegate" that takes an integer parameter and returns void?

What is a delegate in C#?

Виберіть правильну відповідь

question-icon

Which of the following is a correct syntax to declare a delegate named "MyDelegate" that takes an integer parameter and returns void?

Виберіть кілька правильних відповідей

Все було зрозуміло?

Секція 2. Розділ 1
some-alt