为什么我在以下代码中收到此错误?
void Main()
{
int? a = 1;
int? b = AddOne(1);
a.Dump();
}
static Nullable<int> AddOne(Nullable<int> nullable)
{
return ApplyFunction<int, int>(nullable, (int x) => x + 1);
}
static Nullable<T> ApplyFunction<T, TResult>(Nullable<T> nullable, Func<T, TResult> function)
{
if (nullable.HasValue)
{
T unwrapped = nullable.Value;
TResult result = function(unwrapped);
return new Nullable<TResult>(result);
}
else
{
return new Nullable<T>();
}
}