为什么System.Int32是struct而System.String是类 [英] Why System.Int32 is struct and System.String is class
本文介绍了为什么System.Int32是struct而System.String是类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从我开始进行 c#
编程的那一刻起,这确实是我心中的问题。
This was really a question in my mind right from the point, where I started c#
programming.
为什么 int
是 struct
类型
和 string
是类
类型
推荐答案
因为 int
具有固定的长度,而 string
的长度是可变的。因此,编译器可以为 int
s保留一个固定区域(通常在堆栈上),并且它必须为 string保留一个灵活的缓冲区
堆上的char数组。
Because int
has a fixed length, while string
length is variable. Therefore, the compiler can reserve a fixed area for int
s (mostly on the stack), and it must maintain a flexible buffer for a string
s char array on the heap.
这篇关于为什么System.Int32是struct而System.String是类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文