Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I want to know the answer of all three questions.


1)what is the size of Empty class?I think it is 0 Correct me


2) class a {
int a
string waqar
 // Abstract members and properties
    public abstract void RenameFolder();
    public abstract string FolderName
    { 
      get;
      set;
    }
}

or you can take another example

3)Class b  
{
virtual void shape(
//method body
)

}


& also what is the size of the class in #2 & #3

[Edited]Code is wrapped in "pre" tags[/Edited]
Posted
Updated 18-Aug-11 8:45am
v3
Comments
Tamer Hatoum 18-Aug-11 14:46pm    
you mean the size of the file o the hard disk??? just you can check after creating the class file in your project folder...
Smithers-Jones 18-Aug-11 15:33pm    
Posted as solution by Ali Waquar: "no ,, in memory.. some one asked me these question.. i want to know that how much i was rite..." - Don't post "fake" solutions, post either a comment or improve your question.

1 solution

Why should an empty class be zero bytes? A class does not really have a size at all, except in terms of an instance - and a class instance variable will always return 4 or 8 as the size (the size of a pointer to the actual instance).

An empty class isn't empty anyway: it has a name, it is associated with a namespace, it has an inheritance (from Object if nothing else), it may have properties, fields, members. Since these can be retrieved by reflection they must be stored somewhere, and so should (probably) be included in the class "size".

Have a look at google - there is some interesting discussion on class size, and what it actually is! It's not as easy as you think...
 
Share this answer
 

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