Son*_*nül 1 .net c# unsigned signed string-length
在C#编程语言(涵盖C#4.0)(第4版),1.3类型和变量,第9页.
Hooray for byte是一个无符号类型!事实上,在Java中,一个字节被签名(并且没有无符号的等价物),这使得很多无意义的错误容易出错.很可能我们都应该比我们更多地使用uint,请注意:我确信许多开发人员在需要整数类型时默认达到int.框架设计者当然也属于这一类:为什么String.Length应该签名?
当我反编译String.Length ;
/// <summary>
/// Gets the number of characters in the current <see cref="T:System.String"/> object.
/// </summary>
///
/// <returns>
/// The number of characters in the current string.
/// </returns>
/// <filterpriority>1</filterpriority>
[__DynamicallyInvokable]
public int Length { [SecuritySafeCritical, __DynamicallyInvokable, MethodImpl(MethodImplOptions.InternalCall)] get; }
Run Code Online (Sandbox Code Playgroud)
也在MSDN中 ;
Length属性返回此实例中Char对象的数量,而不是Unicode字符数.原因是Unicode字符可能由多个Char表示.
它返回当前字符串中的字符对象数.为什么在已经存在类型的情况下String.Length返回?什么是的点和?Int32UInt32signed-unsigned byteString.Length
Rob*_*vey 10
Int32被广泛认为是.NET框架中的"通用"整数.如果您需要一个非小数的一般数字,Int32那么您首先要达到的数字.如果您有特定原因,则只能使用其中一种无符号类型.
使用int所有Count属性可创建一致的API,并允许使用-1作为标志值(框架中的某些API可以使用).
来自http://blogs.msdn.com/b/brada/archive/2003/09/02/50285.aspx:
我们许多人的普遍感觉是,绝大多数编程都是使用签名类型完成的.无论何时切换到无符号类型,都会强制进行心理模型切换(以及丑陋的转换).在最糟糕的演员阵容中,您构建了一个完全并行的API世界,它采用无符号类型.
| 归档时间: |
|
| 查看次数: |
690 次 |
| 最近记录: |