相关疑难解决方法(0)

接线员'?' 不能应用于'T'类型的操作数

试图制作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单线程.

c# generics delegates c#-6.0 null-propagation-operator

23
推荐指数
2
解决办法
4811
查看次数