Replies: 3 comments 10 replies
-
It is not a bug. int and int? are two different types. Specifically int? is really Nullable. T? means something different for value types and reference types. Since you are specifying your first method with int? (aka Nullable, As far as I know your best bet is to create 2 different GetDefaultNullable methods one for value and one for reference types. Edit: Nullable is a value type, as I has just learned. Still the answer is that default(int) is 0. |
Beta Was this translation helpful? Give feedback.
-
No, it's evolution. Before C# 9.0 |
Beta Was this translation helpful? Give feedback.
-
When |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I found this weird situation in the C# language where if I call a generic function and pass in a value type (e.g .
int
), then if I pass that value type parameter into another generic function but in nullable format (e.g .T?
, which should resolve toint?
), then the nullability of the type is erased, and the second generic function sees only the original non-nullable value type (int
):Is this a bug in the type system? It's really frustrating me because I have to resort to reflection to get the correct nullable type that I want, and that's tricky and error prone.
Beta Was this translation helpful? Give feedback.
All reactions