如何在 C# 中为泛型方法设置仅对整数类型的限制(byte、sbyte、short、ushort、int、uint、long、ulong)
public T example<T>(this T value) where T (...)????
如何在 C# 中为泛型方法设置仅对整数类型的限制(byte、sbyte、short、ushort、int、uint、long、ulong)
public T example<T>(this T value) where T (...)????
没门。只有以下构造可以用作对泛型的限制:
以下选项可用作解决方法:
T不受约束并在方法开始时检查类型(出于显而易见的原因,这是一个“较弱”的解决方案)