Cs8506 не удалось найти лучший тип для выражения switch
Обновлено: 04.11.2024
I have created a running example in sharplab. if switch expression contains the string or other objects it runs fine.
working example 1:
working example 2:
Error example:
original problem (needs fixing):
Thanks to Pavel and Marc, below is the fix:
Follow3 Answers 3
You should explicitly declare a type of handler, instead of var
In your sharplab sample both handlers implement IHandler interface and inherit BaseHandler class, compiler simply doesn't know which type to use, you should tell it him explicitly
The same is true for the dependency injection sample, you should explicitly declare a type (assuming that Handler1 and Handler2 implement IHandler )
You can do it only for one constant, compiler is smart enough to do the rest of job for you
Читайте также: