开发者

Difference between initializing a string and not initializing a string in .NET

I would like to know how is memory allocated when initializing a string using the new keyword and when setting a value to the string without 开发者_如何学运维the new keyword.

Abishek R Srikaanth


There is no difference between the way you initialize it with new keyword or when you directly set the string using '='. The memory is both allocated on the heap and so garbage collector is reponsible for collecting the memory once it goes out of scope. The only differentce is 'new' calls the constructor whereas if you directly assign using = the overloaded operator gets called and it initializes a new instance of the string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜