问题描述
虽然读到C#中的所有内容都是一个对象,但为什么我能这样做:
string temp ="" ;;
而不是
string temp = new string("");
这只是编译器提供的快捷方式吗?
While reading that everything in C# is an object, why is it that I can do:
string temp = "";
instead of
string temp = new string("");
Is this just a shortcut the compiler provides?
推荐答案
你认为第二个会调用什么构造函数?
代码中存在的字符串文字确保带有
的字符串适当的数据在运行时可用。字符串被实习,
所以只有一个对象为所有具有相同数据的文字创建。
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
What constructor would you believe the second would call?
A string literal being present in code makes sure that a string with
the appropriate data in is available at run time. Strings are interned,
so that only one object is created for all literals with the same data.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于C#对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!