试图使Feature
通用,然后突然编译器说
操作员 '?' 不能应用于“T”类型的操作数
这是代码
public abstract class Feature<T>
{
public T Value
{
get { return GetValue?.Invoke(); } // here is error
set { SetValue?.Invoke(value); }
}
public Func<T> GetValue { get; set; }
public Action<T> SetValue { get; set; }
}
可以改用此代码
get
{
if (GetValue != null)
return GetValue();
return default(T);
}
但我想知道如何修复那个漂亮的 C# 6.0 单线。