The C# specification states that 0 (and only zero) is implicitly convertible to any enum type:
6.1.3 An implicit enumeration conversion permits the decimal-integer-literal 0 to be converted to any enum-type and to any nullable-type whose underlying type is an enum-type.
If you don't explicitly assign your enumerations with values, they are 0..n, so Type1
is 0 in your case. This behavior has nothing to do with property indexers.
Since zero is the only implicit conversion that exists, this will compile fine:
IEnumerable<CustomMessage> x2 = cml[0];
But this will not compile because there is no implicit conversion for 1:
IEnumerable<CustomMessage> x2 = cml[1];
In that case, you would need to explicitly convert the value:
IEnumerable<CustomMessage> x2 = cml[(MessageType)1]; //Compiles fine