字符串s =新字符串()之间的差异;和字符串s ="abv"; [英] Differences between string s= new string (); and string s=“abv”;

查看:159
本文介绍了字符串s =新字符串()之间的差异;和字符串s ="abv";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我知道这两个对象创建之间的区别..在第一种情况下,将在堆区域中创建对象,但是在第二种情况下,将在字符串常量池(scp)区域中创建对象.

Please Let Me Know The differences Between These Two Object Creation.. In the First Case object will be created in Heap Area But In second Case Object Will Be created in String Constant Pool (scp) Area ..Is It The Answer or something else.

推荐答案

根本不正确.这种类型的设计更为明智:没有此类构造函数.这些构造函数不存在:string(); string(string);根本不需要,并且甚至有害.

您提到了.它也没有您所想的那样起作用,它被称为实习生池.请阅读有关实习的信息;很有意思:
http://en.wikipedia.org/wiki/String_intern_pool [ http://msdn.microsoft.com/zh-CN /library/system.string.intern(v=vs.110).aspx [ http://msdn.microsoft.com/zh-CN /library/system.string.isinterned(v=vs.110).aspx [
Not true at all. This type is designed in much wiser way: there is no such constructor. These constructors do not exist: string(); string(string); the are simply never needed and having them would be even harmful.

You mentioned the pool. It also does not work as you thought, and it is called intern pool. Please read about interning; it is very interesting:
http://en.wikipedia.org/wiki/String_intern_pool[^],
http://msdn.microsoft.com/en-us/library/system.string.intern(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.string.isinterned(v=vs.110).aspx[^].

—SA


这篇关于字符串s =新字符串()之间的差异;和字符串s ="abv";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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