试图制作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; }
}
Run Code Online (Sandbox Code Playgroud)
可以使用此代码
get
{
if (GetValue != null)
return GetValue();
return default(T);
}
Run Code Online (Sandbox Code Playgroud)
但我想知道如何修复那个漂亮的C#6.0单线程.