Click here to Skip to main content
15,891,850 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,
Can we consider a Two dimension array as an object? I want to have an arraylist which members are 2 dimension arrays.

Is it possible?

Please help me.

Thanks in advance
Posted
Updated 28-Jun-11 19:52pm
v2

Everything, absolutely everything is an object, even non-boxed constant 1. In a wider sense of this word, objects in the sense of OOP are all objects of class and structure types, all arrays and boxed forms of primitive types and enumerations.

Also, delegate and event instances are objects of some implicitly defined classes. You can find it out if you use GetType() and Reflection on those instances.

This is much more delicate matter. Please see my past answer and recent article:
Confusion about delegates[^],
Dynamic Method Dispatcher[^].

Now. Never use ArrayList! This class is made obsolete with v.2.0 when generics were introduced. Use System.Collections.Generic.List instead. The element type can be absolutely anything. Even the same type as the list itself, which makes a tree structure.
(See my recent answer: where're we can find a open source c# tree structure[^].)

This should answer your question.

—SA
 
Share this answer
 
Yes you can do. But I would suggest you to have a generic list instead of arraylist.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 3:06am    
Correct, my 5.
There is more to it. Please see my answer.
--SA
1. Even primitive data types are objects in .Net. If they are value types they are treated a little differently, but they are still objects.

2. Arrays are not a good choice in many cases because you must set their dimensions beforehand, but still you might put them into lists. Why don't you simply try it out?

3. Even if they were value types or were no objects, you could still wrap them up in an object and then put those in your list.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 3:07am    
You forgot about boxing/unboxing. I voted 5 anyway.
There is more to it; please see my answer.
--SA
[no name] 29-Jun-11 3:48am    
Thanks, I have returned that courtesy. Of course you're right, but I was out of time and had to finish the answer and then turn off the computer and leave the house. I think, for the beginning it is important to understand that there are value types which are treated a little differently than reference types, but under the hood they are all objects. Once you got accustomed to that, you can also worry about boxing/unboxing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900