CopyInsert( )
would not compile because
int
is a value type, not a reference type:
// Now wrong because T must be reference type!
ArrayUtils.CopyInsert(99, 2, nums, nums2); // Now illegal!
Generic Delegates
Like methods, delegates can also be generic. To declare a generic delegate, use this general
form:
delegate
ret-type delegate-name
<
type-parameter-list
>(
arg-list
);
Notice the placement of the type parameter list. It immediately follows the delegate’s name.
The advantage of generic delegates is that they let you define, in a type-safe manner, a
generalized form that can then be matched to any compatible method.
The following program demonstrates a generic delegate called
SomeOp
that has one
type parameter called
Do'stlaringiz bilan baham: |