Why is unconstrained T?
allowed when T
is not decorated with notnull
?
#5362
Replies: 2 comments 16 replies
-
It could make a lot of sense. Imagine There's no necessary connection that I see that says As the author of the same class, don't write |
Beta Was this translation helpful? Give feedback.
-
Instead of foobaring let's see some meaningful example: // notnull for TKey, whereas TValue is not decorated by anything
class SomeDictionary<TKey, TValue> where TKey: notnull
{
// TValue? is totally meaningful here, regardless of any constraint
public TValue? GetValueOrDefault(TKey key} => ...;
} Both |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I looked at the LDMs here and here and found no mention of using
notnull
to prohibit unconstained nullable generics. Was it ever brought up?Beta Was this translation helpful? Give feedback.
All reactions