w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
What does the class type constraint achieve if a generic type constraint must also implement an interface in c#

Structs can implement interfaces. So this

where T : class, IMyInterface

demands both the type T be a class and a class which implements the interface called IMyInterface.

For instance this is the declaration of Int32 structure:

public struct Int32 : IComparable, IFormattable, 
                      IConvertible, IComparable<int>,

as you can see here.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.