• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1011
  • Last Modified:

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
0
tracy_p
Asked:
tracy_p
1 Solution
 
pollock_dCommented:
you can't convert an orange into an apple........but you can convert them into fruit....
0
 
prosh0tCommented:
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.
0
 
Joel CoehoornDirector of Information TechnologyCommented:
0
 
tracy_pAuthor Commented:
i am calling a function of one class into a function of another class.is this something wrong??
0
 
prosh0tCommented:
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.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now