C# size of objects question  
Author Message
dudu sananes





PostPosted: Visual C# General, C# size of objects question Top

I'm not sure about the size of objects in c#.
Lets say I have two classes: Dog, Cat
Class Dog
{
int a;
int b;
int c;
Cat cat;
}

Class Cat
{
int a;
int b;
int c;
}

What is the size of class Dog, to be specific, does the object cat adds to the size of Dog 4 bytes (pointer) or 12 bytes (3 variables of int)




Visual C#3  
 
 
Matthew Watson





PostPosted: Visual C# General, C# size of objects question Top

Classes are reference types, so it would add the size of a pointer.


 
 
Paul Louth





PostPosted: Visual C# General, C# size of objects question Top

"Cat cat" is a referrence to a Cat so Dog is 16 bytes.  If you changed "class Cat" into "struct Cat"', then the size of Dog would be 24 bytes.
 
 
dudu sananes





PostPosted: Visual C# General, C# size of objects question Top

OK, 10x alot