I am playing with Span in C#.
Am I right that I cannot use switch statement with span I have to write methods like this?
private int GetNumberOfLegs(ReadOnlySpan<char> animal)
{
if (animal.SequenceEqual("dog".AsSpan()))
return 4;
if (animal.SequenceEqual("cat".AsSpan()))
return 4;
if (animal.SequenceEqual("spider".AsSpan()))
return 8;
if (animal.SequenceEqual("bird".AsSpan()))
return 2;
throw new NotSupportedException($"Uknown animal {animal.ToString()}");
}
Is there better way to express this algorithm with Span?