enum Gender { Male, Female }
var k = new[] { Gender.Male }.Cast().ToList().Cast().ToList(); //alright
var p = new[] { Gender.Male }.Cast<
This is due to deferred execution. The latter statement actually tries to cast Gender.Male
to int?
. In contrast, the first statement actually performs the cast operation to an int
and gets a List
before deferring the execution to cast those to int?
; clearly int
to int?
has an implicity conversion defined already.