这两者之间有什么区别,我应该使用哪一个?
string s = "Hello world!";
String s = "Hello world!";
string https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string是 C# 中的别名System.String https://learn.microsoft.com/en-us/dotnet/api/system.string.
所以从技术上来说,没有什么区别。就像是int vs. System.Int32 https://stackoverflow.com/questions/62503/c-int-or-int32-should-i-care.
就指南而言,通常建议使用string
任何时候你指的是一个对象。
e.g.
string place = "world";
同样,我认为通常建议使用String
如果需要具体参考班级。
e.g.
string greet = String.Format("Hello {0}!", place);
这是微软倾向于使用的风格他们的例子 https://learn.microsoft.com/en-us/dotnet/api/system.string.format#examples.
看来该领域的指导可能已经改变,因为StyleCop https://github.com/StyleCop现在强制使用 C# 特定别名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)