Replies: 3 comments 5 replies
-
Both of those shouldn't change, IMO. The only time a |
Beta Was this translation helpful? Give feedback.
-
|
I think that when a developer uses closed types, it's most likely out of a desire for exhaustiveness to be explicitly considered at use sites. So, I feel that non-exhaustive switch statements over closed types should result in a warning by default. If you do not want to be prompted to handle new cases for a closed type that are added over time, you should explicitly put a default label in the switch statement. Or, if you don't want the enforcement across the board, put closed enum MyEnum { One, Two, Three }
void M(MyEnum e)
{
switch (e)
{
case MyEnum.One: HandleOne(); break;
case MyEnum.Two: HandleTwo(); break;
} // warning: switch is non-exhaustive
switch (e)
{
case MyEnum.One: HandleOne(); break;
case MyEnum.Two: HandleTwo(); break;
case MyEnum.Three: HandleThree(); break;
} // ok, and will warn again if a new case is added later.
switch (e)
{
case MyEnum.One: HandleOne(); break;
case MyEnum.Two: HandleTwo(); break;
default: HandleDefault(); break;
} // ok, and will never warn again about new cases.
}Handling of "nested patterns over closed types", I'm less sure about. Possibly a similar switch over type |
Beta Was this translation helpful? Give feedback.
-
|
I don't see the need for the public class Animal
{
private Animal( ... ) { ... }
....
public class Dog : Animal { ... }
public class Cat : Animal { ... }
}which would prevent other classes from inheriting from One can even use the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-10-01.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions