J
Jon the Blind
I would greatly appreciate if someone could shed some light on this.
In a class inherited from CollectionBase, I have a function something like
this:
Public Function ToArray() As Widget()
Return CType(MyBase.InnerList.ToArray, Widget())
End Function
This is meant to return the contents of the collection as an array (!). When
running the code, I get an InvalidCastException here, but if I break into
the code and run just
?CType(MyBase.InnerList.ToArray, Widget())
in the Immediate Window, I don't get the exception.
Runnning this in the Immediate Window gets an interesting result:
?CType(MyBase.InnerList.ToArray, Widget()).GetType.ToString
"System.Object[]"
Assuming I'm not putting too much faith in the Immediate Window replicating
the behavior of the runtime, is this an error with the CType function? Or am
I missing something fundamental?
Any insight is appreciated.
Regards,
Jon
In a class inherited from CollectionBase, I have a function something like
this:
Public Function ToArray() As Widget()
Return CType(MyBase.InnerList.ToArray, Widget())
End Function
This is meant to return the contents of the collection as an array (!). When
running the code, I get an InvalidCastException here, but if I break into
the code and run just
?CType(MyBase.InnerList.ToArray, Widget())
in the Immediate Window, I don't get the exception.
Runnning this in the Immediate Window gets an interesting result:
?CType(MyBase.InnerList.ToArray, Widget()).GetType.ToString
"System.Object[]"
Assuming I'm not putting too much faith in the Immediate Window replicating
the behavior of the runtime, is this an error with the CType function? Or am
I missing something fundamental?
Any insight is appreciated.
Regards,
Jon