Built-in delegates
In C#, not only are we able to declare a delegate, but we are also able to use the built-in delegate from the C# standard library. This built-in delegate also applies to the generic data type, so let's discuss the generic delegate prior to discussing the built-in delegate.
Generic delegates
A delegate type can use a generic type as its parameter. Using the generic type, we can put off the specification of one or more types in parameters or return values until the delegate is initialized into a variable. In other words, we do not specify the data types of the delegate's parameters and return values when we define a delegate type. To discuss this in more detail, let's take a look at the following code, which we can find at GenericDelegates.csproj
:
public partial class Program { private delegate T FormulaDelegate<T>(T a, T b); }
We have a delegate name, FormulaDelegate
, using the generic data type. As we can see, there is a T
symbol, which represents...