我该如何解决这个错误消息?
static public class Blah
{
public static T val<T>(this bool b, T v) { return b == true? v:0; }
}
错误
Type of conditional expression cannot be determined because there is no implicit conversion between 'T' and 'int
最佳答案
如果您希望 T 是一个 int,接受一个 int 而不是 T。否则,如果 b == false,请考虑返回 default(T)。
返回 b ? v : 默认(T);
如果T是int,则返回0。如果是引用类型,则返回null。不断……
关于c# - 将 T 限制为 int 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2700419/