Seeing as C# can\'t switch on a Type (which I gather wasn\'t added as a special case because is relationships mean that more than one distinct
switch
is
C# 8 enhancements of pattern matching made it possible to do it like this. In some cases it do the job and more concise.
public Animal Animal { get; set; } ... var animalName = Animal switch { Cat cat => "Tom", Mouse mouse => "Jerry", _ => "unknown" };