On Thu, 09 Oct 2008 20:16:57 -0700, Rene <a@b.comwrote:
If variance/covariance is not allowed in array of value types, why is
the expression on the "Main" method run successfully (see snippet
below)? I am missing something?
I think so. But it's not necessarily something obvious. :)
A question nearly the same as yours came up a few months ago. You might
find that thread relevant in addressing your question:
http://groups.google.com/group/micro...1bf036a23918e/
The big difference between that thread and your question is that in the
previous thread, the person was using the "as" operator, whereas you're
using a cast. But I think in this particular example, the two are
basically equivalent (except for what happens on an error). That is, the
statement is legal C# and the error-checking is done by the CLR, which
allows it because the underlying enum types are the same.
In other words, I think that this particular array cast is in fact legal.
It's not a bug for it to work.
Pete