【发布时间】:2019-02-05 09:03:23
【问题描述】:
在 C# 中我们可以编写
Int a=new int();
char a=new Char();
person p=new person();
person 是一个类。
那么为什么我们不能写
string s =new string();
毕竟字符串是引用类型。 那为什么不行呢?
【问题讨论】:
-
有几个字符串构造函数,见msdn.microsoft.com/en-us/library/…。没有没有参数的构造函数,因为无论如何你都可以使用 string.Empty 。这并不少见,在框架和其他地方,您经常会发现类只有带有参数的构造函数。
标签: c# string primitive-types reference-type