I have the following C# code:
AnimalTypeEnum animal;
string s = Console.ReadLine();
switch (s.ToLower())
{
case \"dog\":
animal = AnimalTypeEnum.DOG;
In case s.ToLower()
is something else that dog
, cat
or rabbit
, animal
has no value.
You should add default in your switch for that case:
switch (s.ToLower())
{
case "dog":
animal = AnimalTypeEnum.DOG;
break;
case "cat":
animal = AnimalTypeEnum.CAT;
break;
case "rabbit":
animal = AnimalTypeEnum.RABBIT;
break;
default:
animal = ...
break;
}