to an object. This means that for the first increment, a new object is required.
534
P a r t I :
T h e C # L a n g u a g e
A type parameter for a generic interface can have constraints in the same way as it can
for a generic class. For example, this version of
ISeries
restricts its use to reference types:
public interface ISeries where T : class {
When this version of
ISeries
is implemented, the implementing class must also specify the
same constraint for
T
, as shown here:
class ByTwos : ISeries where T : class {
Because of the reference constraint, this version of
ISeries
cannot be used on value types.
Thus, in the preceding program, only
ByTwos
would be valid.
Do'stlaringiz bilan baham: