Link to home
Create AccountLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net/VB 2005 Using multiple types in an array

Hi

I am working in Visual Studio 2005.
Is it possible to use mutliple types with the same array

eg Dimm arr(10) as Object

arr(0) = "Hello"
arr(1) = False
arr(2) = 23
etc
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Murray Brown

ASKER

Thanks for that!
The dimm was a typo.
Appreciate the quick answer!
Note, though, that this is really a case of using subclasses, and everything being a subclass of Object.

If you declared

dim arr(10) as Shape

And Circle, Square, and Triangle all interited from Shape, you could put
Circles Squares and Triangles in arr ... but not, for example, an arraylist.
I think I understand your last comment.
I just want to be able to eg do the following
Dim A(2) As Object
A(0) = "Tree"
A(1) = xlYesNoGuess.xlYes
A(2) = 3456376

I am assuming that this is okay.

Thanks
That will WORK, but it is dangerous.

Later, when you reference A(2)...and maybe expect to find a string rather than a number...you might blow up.

It is generally good programming practice to make the type of the Array as specific as possible, to minimize the chance of a type mismatch in the future.
Thanks