CS8603 Warning When Using Multiple Fields in Switch Expression #8513
-
Hello private static object GetSortingValue(SomeClass obj, SomeEnum field)
{
return field switch
{
SomeEnum.Field1 => obj.Field1,
SomeEnum.Field2 => obj.Field2,
SomeEnum.Field3 => obj.Field3,
SomeEnum.Field4 => obj.Field4,
SomeEnum.Field5 => obj.Field5,
SomeEnum.Field6 => obj.Field6,
_ => throw new ArgumentOutOfRangeException(nameof(field))
};
} This code triggers a CS8603 warning, requiring the return type to be nullable. However, if the Can someone explain why this warning happens and suggest the best way to handle it? Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
KennethHoff
Oct 14, 2024
Replies: 1 comment 1 reply
-
We would need to know what the fields of |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
KalumeC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We would need to know what the fields of
SomeClass
are