Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Delegates | Interactive GUI
C# Desktop Development with .NET MAUI

Delegates

Svep för att visa menyn

Note
Note

According to some definitions of signature, a method's return type is not considered part of its signature. For example, in the context of method overloading, the return type is not included when referring to a method's signature.

However, in the context of delegates, the term signature refers to both the return type and the parameter list of a 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?

question mark

What is a delegate in C#?

Vänligen välj det korrekta svaret

question mark

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

Välj alla rätta svar

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 1

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Delegates

Note
Note

According to some definitions of signature, a method's return type is not considered part of its signature. For example, in the context of method overloading, the return type is not included when referring to a method's signature.

However, in the context of delegates, the term signature refers to both the return type and the parameter list of a 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;
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 1
some-alt