Since C# 8.0, the standard is non nullable variable by default. Ref1
But in case of generics like this one:
public static T PerfomIO<T>(Func<T> function, T defaultValue = default)
{
try
{
return function();
}
catch (IOException)
{
}
return defaultValue;
}
How to get rid of the compilation error "CS8601 Possible null reference assignement" that occur when I try to pass "default" ?
I want to support null value here. I do not want to disable the error message. I want to program it the way it should be.
I try to add Nullable in many ways without success. I try [AllowNull] without success
public static T MyFunc<T>(Func<T> function) { return MyFunc(function, default); }
– Ride