String.IsNullOrEmpty或string.IsNullOrEmpty

Nei*_*ght 15 .net c# compiler-construction

我一直在查看过去3天的代码,原始开发人员使用String类而不是字符串类来定义字符串.因此,当他们使用IsNullOrEmpty方法时,它定义了String.IsNullOrEmpty.

我想知道的是编译器处理String.IsNullOrEmptystring.IsNullOrEmpty相比如何?

使用String.IsNullOrEmptystring.IsNullOrEmpty有什么优势吗?

log*_*cnp 19

它们都是一样的.

string是C#中System.String的关键字别名.

唯一不同的是,当使用String时,您需要使用System.String.IsNullOrEmptyusing System;在代码文件的开头.

  • 创建一个名为StringUtilities的静态类,并定义一个名为IsNullOrEmpty的扩展方法:public static bool IsNullOrEmpty(this string @this){return string.IsNullOrEmpty(@this); }.这允许您将其作为要检查的变量的方法来调用,例如fred.IsNullOrEmpty(). (6认同)

šlj*_*ker 5

String代表System.String,它是.NET Framework类型.string是 System.String的C#语言中的别名.它们都被编译为IL(中间语言)中的System.String,因此没有区别.选择你喜欢的并使用它.如果您使用C#编写代码,我更喜欢字符串,因为它是C#类型的别名,并且是C#程序员所熟知的.

我可以说同样的(int,System.Int32)等.