> C# doesn’t support parameterised enums like typescript and rust do
To be fair, you rarely miss them with pattern matching and records. In a similar vein to a sibling comment:
var animal = ...
Console.WriteLine(animal switch {
Animal.Dog(_, var cats) => $"Chased {cats} cats",
Animal.Cat or Animal.Bat => "No cats chased",
_ => "Unknown animal"
});
abstract record Animal(string Name) {
public record Dog(string Name, int CatsChased): Animal(Name);
public record Cat(string Name): Animal(Name);
public record Bat(string Name): Animal(Name);
}
There are many libraries to further enhance the experience, provide additional exhaustiveness analysis, etc.
To be fair, you rarely miss them with pattern matching and records. In a similar vein to a sibling comment:
There are many libraries to further enhance the experience, provide additional exhaustiveness analysis, etc.