当编写通用的方法和功能,我看到写为什么类的类型约束实现,如果一个泛型类型约束也必须实现在C#中的接口
public static void MyMethod<T>(params T[] newVals) where T : IMyInterface
也
何处类型约束public static void MyMethod<T>(params T[] newVals) where T : class, IMyInterface
'类'类型约束添加任何东西 - 我不认为一个结构可以实现一个接口,但我可能是错的?
谢谢
是结构'can'实现接口。 –
是的,结构可以实现接口。请参阅:[Int32结构](http://msdn.microsoft.com/en-us/library/system.int32(v = vs.110).aspx) –
'Enumerator'是一个结构的示例,它实现了一个接口。 http://stackoverflow.com/questions/521298/when-to-use-struct-in-c –