我想使用约束来限制 N 可以接受的可能类型。我希望将 N 限制为整数或小数。
public static Chart PopulateInto<T, N>(List<T> yAxis, List<N> xAxis) where N : int, decimal
{
// Do stuff here
}
感谢任何帮助...
最佳答案
不可能将泛型参数限制为特定值类型。
然而,您可以通过添加 where N : struct
强制它成为a 值类型或struct
,但仅此而已。
关于c# - 如何使用约束将 T 限制为值类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109500/