不同条件下的班级人数是多少? [英] what is the Size of class in different criteria.

查看:98
本文介绍了不同条件下的班级人数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道所有三个问题的答案.


1)Empty类的大小是多少?我认为是0纠正我


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
)

}



&还有#2&中的班级人数是多少#3

[Edited]代码包装在"pre"标签中[/Edited]



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

Code is wrapped in "pre" tags[/Edited]

推荐答案

为什么一个空类应该为零字节?除了实例之外,一个类实际上根本没有大小.类实例变量将始终返回4或8作为大小(指向实际实例的指针的大小).

空的类无论如何都不是空的:它有一个名称,它与一个命名空间相关联,它有一个继承(如果没有其他情况,则继承自Object),它可能具有属性,字段,成员.由于可以通过反射来检索它们,因此必须将它们存储在某个位置,因此(可能)应该包括在大小"类中.

看看google-关于班级人数及其实际含义的一些有趣的讨论!这并不像您想的那么容易...
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...


这篇关于不同条件下的班级人数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆