How can i solve this error msg?
static public class Blah
{
public static T val<T>(this bool b, T v) { return b == true? v:0; }
}
error
Type of conditional expression cannot be determined because there is no implicit conversion between 'T' and 'int
There is no way to do this in C#. You can do
where T: struct, and force T to be a value type, but that still isn’t enough.Or you can do
default(T), which is 0 when T is an int.