C#中string和String的区别

首先运用MSDN官网的解释:The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.

             说的是string类型其实代表了一种统一编码的特性,在.net framwork  中"string"是System.String的一个别名而已。

 

再引用一个博客的理解:http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-s-the-difference-between-code-string-code-and-code-system-string-code.aspx :

C# defines a number of aliases for CLR types. They may be used interchangably, and even mixed together, e.g.

string x = new System.String(' ', 5);.

These are the aliases defined:

AliasCLR type
stringSystem.String
sbyteSystem.SByte
byteSystem.Byte
shortSystem.Int16
ushortSystem.UInt16
intSystem.Int32
uintSystem.UInt32
longSystem.Int64
ulongSystem.UInt64
charSystem.Char
floatSystem.Single
doubleSystem.Double
boolSystem.Boolean
decimalSystem.Decimal

说在C#中为CLR类型定义了很多的别名,说明string其实和String的用法一样,只不过是不同程序员的使用习惯罢了。我也看了一些别人的理解,string其实在C#语言中是一种标记,也就是string是C#中的关键字他代表了framwork中的String类型,所以毫无疑问既然是关键字string就不能作为其他任何类型变量的名字了。编译器在解释的时候吧string编译为String类型,由此可见如果用String就能减少编译器的一些负担,提高运行效率。

 

推荐一个详细的地址:http://www.cnblogs.com/aidd2008/archive/2008/12/07/1349269.html

转载于:https://www.cnblogs.com/2012-10-3/articles/2375525.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值