I encountered this while enabling the nullable feature in our projects.
In Net 5.0 the signature for object.ToString() is
public virtual string? ToString ();
Why is that? The notes to Inheritors even state
Your ToString() override should not return Empty or a null string.
so why does the signature state that it can? I could not find any info on that.
But my ideas are
- Backwards comparability for those people who didn't read the note mentioned above and return null from their ToString method.
- To let the people who read the mentioned note ignore it
But since we want to treat the warnings that come with the nullable feature as errors now we have to add ! or a null check everywhere we use ToString.
Is there any other good reason why the signature is as it is?