I would not have thought that its possible, but it seems you somehow can create and fill an C# array of a "wrong" type.
I stumbled upon the following anomaly in Unity 4.2.1 today:
Editor[] editors = ActiveEditorTracker.sharedTracker.activeEditors;
Debug.Log(editors.GetType().Name);
Debug.Log(editors.GetType().GetElementType().Name);
Debug.Log(typeof(Editor).IsAssignableFrom(editors[0].GetType()));
Debug.Log(typeof(Editor).IsAssignableFrom(editors.GetType().GetElementType()));
It prints the following output:
MonoBehaviour[]
MonoBehaviour
True
False
In Unity, the class "MonoBehaviour" and "Editor" are unrelated slibbings (both inherit from UnityEngine.Object, but neither from the other). They are not assignable to each other or related in any way I can see that would make the above output possible.
So my question is: The Heck?
More detailed question: How is it possible to create an array of the "wrong" type and fill it with elements of the "right" type? I want to do this too! How do I circumvent the array checks from C#? (maybe using unsafe()?)
My current gut-feeling is, that C# only prevent writing to the wrong array (via ArrayTypeMismatchException), but if you somehow magically fill the array (in case of Unity, probably using dark C++ magic), it just works..?
(Funny also: If I do this editors[0] = editors[0]
I get the mentioned ArrayTypeMismatchException)
Edit: Also funny: Array self = editors; editors = (Editor[])self;
throws an InvalidCastException