Easy question about array

T

Tony Johansson

Hello!

As I have understood this it means the following. Correct me if I'm wrong.
You store type objects in the array obj and the first one is refering to
a and the second is refering to b and the third is refering to c.
You store reference types of type object in the array but all of them is
refering to value types(a,b,c)

int32 a = 0;
Byte b = 0;
int16 c = 0;
object[] obj = {a,b,c};

It's the same as saying
object o1 = a;
object o2 = b;
object o3 = c;

//Tony
 
D

Duggi

Hello!

As I have understood this it means the following. Correct me if I'm wrong..
You store type objects in the array obj and the first one is refering to
a and the second is refering to b and the third is refering to c.
You store reference types of type object in the array but all of them is
refering to value types(a,b,c)

int32  a = 0;
Byte  b = 0;
int16  c = 0;
object[] obj = {a,b,c};

It's the same as saying
object o1 = a;
object o2 = b;
object o3 = c;

//Tony

Array is a reference type, which holds a series of reference objects
or value type objects.

to know more http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx

-Cnu
 
G

Göran Andersson

Tony said:
Hello!

As I have understood this it means the following. Correct me if I'm wrong.
You store type objects in the array obj and the first one is refering to
a and the second is refering to b and the third is refering to c.
You store reference types of type object in the array but all of them is
refering to value types(a,b,c)

int32 a = 0;
Byte b = 0;
int16 c = 0;
object[] obj = {a,b,c};

It's the same as saying
object o1 = a;
object o2 = b;
object o3 = c;

//Tony

Yes, that is correct.

To store the values in the array, each value is boxed inside an object
that is allocated on the heap.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top