Replies: 7 comments
-
There is an issue #36 about nullable reference type Which I wish it could enable this code instead public void Test<T>(T? value)
{
var x = value ?? default(T);
} |
Beta Was this translation helpful? Give feedback.
-
I'd personally prefer that @Thaina, |
Beta Was this translation helpful? Give feedback.
-
@DavidArno My point is I think we should keep the rule that void Test<T>(T obj) where T : nullable
{
var x = obj ?? default(T);
}
object obj = null;
Test(obj);
int? n = null;
Test(n); |
Beta Was this translation helpful? Give feedback.
-
It does no harm to use ?? if T turns out to be struct. The jitter can elide the check for value types. It gives you the ability to do something you couldn't do before: evaluate the left expression only once. |
Beta Was this translation helpful? Give feedback.
-
I disagree with you. Firstly,
would just spread the "world of Secondly,
means having to introduce a new keyword, which isn't a lightweight thing to do. Just allowing |
Beta Was this translation helpful? Give feedback.
-
I agree with this proposal. It seems very strange that one can write: void Foo<T>(T value) {
if (value == null) throw ...
} But one can't write: |
Beta Was this translation helpful? Give feedback.
-
Related inconsistency with pattern matching (in C# 7.1): |
Beta Was this translation helpful? Give feedback.
-
As metioned in dotnet/roslyn#17754, currently comparison between a unrestricted generic type value and null is supported by the language specification, and the following code is already acceptable:
However, the newer null-coalescing cannot pass the compilation as the following:
Does it possible to add support for this scene?
Thank you~
Beta Was this translation helpful? Give feedback.
All reactions