This code:
var userType = viewModel.UserType == UserType.Sales
? new Sales()
: new Manager();
Gives me this compiler error message:
Type of conditional expression cannot be determined because there is no implicit conversion between 'Models.Sales' and 'Models.Manager'.
Why can I not initialize a var depending on the outcome of a condition? Or am I doing something wrong here?
EDIT: @Tim Schmelter, I didn't saw that post, all I could find were int
and null
, bool
and null
:
But no custom types.