Proposal: Nullable var #6985
Replies: 3 comments
-
Why would you need Either (And, yes, I know that nullable reference types don't exist at runtime - but attributes on the implementation of |
Beta Was this translation helpful? Give feedback.
-
In this case the return value is a value type (since it's a tuple), but your point stands, it's impossible for |
Beta Was this translation helpful? Give feedback.
-
I think this would only be useful in cases where:
As such, to me this seems like it wouldn't be useful that often. And in cases where it would be useful, you could use an extension method instead: public static T? AsNullable<T>(this T value) where T : struct
=> value;
var current = stack.Peek().AsNullable(); |
Beta Was this translation helpful? Give feedback.
-
One of the most useful additions to C# language is
var
keyword, which simplifies declaration of variables, as long as compiler is able to deduce the type automatically.I propose adding an option to quickly and automatically declare nullable type based on non-nullable one. For instance:
This is a small quality-of-life improvement, which may simplify lifes of developers, especially after introducing nullable reference types.
Beta Was this translation helpful? Give feedback.
All reactions