Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1061121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:25:51+00:00 2026-05-16T18:25:51+00:00

How to determine if a Class in .NET is big or small? Is it

  • 0

How to determine if a Class in .NET is big or small? Is it measured on how many it’s attributes or fields, datatype of its attributes/fields? or return type of methods? parameters of it’s methods? access modifier of its methods, virtual methods? thanks..

 class A
{

  string x { get; set; }
}

class B 
{
  int x { get; set; }
}

in this example if I instantiate class A and B like this

 A objA = new A();
 B objB = new B();

Is class objA the bigger one because it holds an String property and objB holds only an Int? although I didn’t set any value to it’s property. thanks

EDIT: Just to clarify my question

suppose i have a class

public class Member
{
    public string MainEmpId { get; set; }
    public string EmpId { get; set; }
}

and another class

public class User
{
    public string AccessLevel { get; set; }
    public string DateActivated { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Mi { get; set; }
    public string Password { get; set; }
    public string UserId { get; set; }
    public string UserName { get; set; }
    public string Active { get; set; }
    public string ProviderName { get; set; }        
    public string ContactPerson { get; set; }
    public string Relation { get; set; }
    public string Landline { get; set; }
    public string MobileNo { get; set; }
    public string Complaint { get; set; }
    public string Remarks { get; set; }
    public string Reason { get; set; }
    public string RoomType { get; set; }
}

if I instantiate it like this

  Member A = new Member();
  User B = new User()

is the object A larger than object B?
I know it’s an odd question but I believe every intantiation of an object eats memory space..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:25:52+00:00Added an answer on May 16, 2026 at 6:25 pm

    The size of a class instance is determined by:

    • The amount of data actually stored in the instance
    • The padding needed between the values
    • Some extra internal data used by the memory management

    So, typically a class containing a string property needs (on a 32 bit system):

    • 8 bytes for internal data
    • 4 bytes for the string reference
    • 4 bytes of unused space (to get to the minimum 16 bytes that the memory manager can handle)

    And typically a class containing an integer property needs:

    • 8 bytes for internal data
    • 4 bytes for the integer value
    • 4 bytes of unused space (to get to the minimum 16 bytes that the memory manager can handle)

    As you see, the string and integer properties take up the same space in the class, so in your first example they will use the same amount of memory.

    The value of the string property is of course a different matter, as it might point to a string object on the heap, but that is a separate object and not part of the class pointing to it.

    For more complicated classes, padding comes into play. A class containing a boolean and a string property would for example use:

    • 8 bytes for internal data
    • 1 byte for the boolean value
    • 3 bytes of padding to get on an even 4-byte boundary
    • 4 bytes for the string reference

    Note that these are examples of memory layouts for classes. The exact layout varies depending on the version of the framework, the implementation of the CLR, and whether it’s a 32-bit or 64-bit application. As a program can be run on either a 32-bit or 64-bit system, the memory layout is not even known to the compiler, it’s decided when the code is JIT:ed before execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: .NET: Determine the type of this class in its static method How
Possible Duplicate: .NET: Determine the type of this class in its static method Hello
Goal: to programmatically determine the sizes (in bytes) of the fields of a class.
Is it possible in C++ to determine number of variables/fields in the generic class?
How does .NET's MessageBox determine its size relative to the resolution of the screen
In VB.NET or C#, is there a way to determine if a class has
I'd like to be able to determine what class will be called given an
Is there any non-hacky way to determine wether a class' superclass implements a particular
Is there a way to determine which ClassLoader loads a specific class? Or more
public class A<T> { public <K> void m(A<K> target) { // determine if T

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.