Size of A Class (object) in .NET

后端 未结 6 958
灰色年华
灰色年华 2020-11-28 09:31

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? par

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 10:12

    When one says class size, I would assume that it means how many members the class has, and how complex the class is.

    However, your question is the size of the memory required when we are creating instance of class. We cannot be so sure about exact size, because .Net framework preserves and keeps the underlying memory management away from us (which is a good thing). Even we have the correct size now, the value might be correct forever. Anyway, we can be sure that the following will take some space in the memory:

    1. Instance variable.
    2. Automatic property.

    So that makes sense to say that User class will take more memory than Member class does.

提交回复
热议问题