Skip to content

[C# Guide] Explain that null is a constant pattern, and won't match any type #1845

Closed
@BillWagner

Description

@BillWagner

Our samples on pattern matching are correct, and we mention that null doesn't match any type in an is or case pattern matching expression.

this topic should add a paragraph or two explaining the behavior for null. We can expand with the justifications:

  1. The existing is expression always returned false for null. It is more consistent for the new extensions to have the same semantics on null.
  2. Having null never match a type means that developers do not need the explicit null check after matching a pattern. That is a factor in favor of this design.
  3. If non-nullable types are added to the language, this decision will make everyone happy.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions