另外,字符串在做加减等操作时,因为string是不变的引用类型,所以等于说只要你对string做了一些操作,那么一般情况下都回生成新的实例。
关于string池,string有一个方法
,这方法就会在string池里面找到与str值相等的string引用并返回,如果你用了这样的方法,可以说是节省了内存空间,但是用多了也不好,因为它会一直占用着不会释放直到CLR终止,也就是说,它会一直存在直到你的程序终止。
参考文章:http://stackoverflow.com/questions/3328707/why-dont-we-use-new-operator-while-initializing-a-string
http://tutorials.csharp-online.net/CSharp_String_Theory%E2%80%94String_intern_pool
http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.ldstr.aspx