We help IT Professionals succeed at work.

value of 1-dimensional array of class1 cannot be converted to value of 1dimensional array of class2 because class1 is not derived from class2.

Hi,
wht does this error mean
value of type '1-dimensional array of class1 cannot be converted to value of 1dimensional array of class2 because class1 is not derived from class2.
using vb.net/.net2.0
Thank you
Comment
Watch Question

you can't convert an orange into an apple........but you can convert them into fruit....

Commented:
Right.  It would help us to get you a solution if you explain why you are trying to convert an array of class1 to class2.  there can be a few things you can do:

1. Derive class1 from class2 (this doesn't sound like the correct solution)
2. Use a generic array or collection object that can store any type of object (ie ArrayList)
3. simply use two arrays

the correct answer really depends upon what you are doing.
Joel CoehoornDirector of Information Technology
CERTIFIED EXPERT

Commented:

Author

Commented:
i am calling a function of one class into a function of another class.is this something wrong??
Commented:
do you mean the classes are different, but they have the same function definitions, and you'd simply like to re-use the array since it is calling the same function?  In that case, that's what you would use interfaces for.  You would define an interface (ie ImyInterface) with that function definition, then have both class1 and class2 implement that interface.  Then you could have both types of objects in the same array of type ImyInterface.

From the sounds of it, though, things would be a lot simpler for you just to have two arrays.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.