While I was studying the delegate which is actually an abstract class in Delegate.cs, I saw the following method in which I don't understand
- Why the return value uses
?though it's already a reference(class) type ?[]?meaning on the parameter
Could you explain?
public static Delegate? Combine(params Delegate?[]? delegates)
{
if (delegates == null || delegates.Length == 0)
return null;
Delegate? d = delegates[0];
for (int i = 1; i < delegates.Length; i++)
d = Combine(d, delegates[i]);
return d;
}
Step by step explanation:
params Delegate?[] delegates- It is an array of nullableDelegateparams Delegate?[]? delegates- The entire array can be nullableSince each parameter is of the type
Delegate?and you return an index of theDelegate?[]?array, then it makes sense that the return type isDelegate?otherwise the compiler would return an error as if you were returing andintfrom a method that returns a string.You could change for instance your code to return a
Delegatetype like this: