【发布时间】:2018-04-19 09:50:01
【问题描述】:
当引用 Jon Skeet 的 this 文章时,我看到在 C# 中 int 将是 4 个字节的内存,而 struct 是这样的:
struct PairOfInts
{
public int a;
public int b;
}
总共将是 8 个字节的内存,因为:
内存槽足够大,可以容纳两个整数(所以它必须是 8 个字节)。
如果我们有这个:
public int a = 0;
public int b = 2147483647; //the max allowed for an int
a 和 b 是否仍然只占用 4 个字节的内存?字符串也一样吗?示例:
public string c = "";
public string d = "somethingreallyreallylong";
【问题讨论】:
-
不,因为没有
string.Maxotstring.Min存在。所以基本上对于值类型是,但对于像string这样的引用类型没有 -
在 C# 中
string是引用类型