String.IsNullOrEmpty(“")或string.IsNullOrEmpty(“") [英] String.IsNullOrEmpty("") or string.IsNullOrEmpty("")

查看:96
本文介绍了String.IsNullOrEmpty(“")或string.IsNullOrEmpty(“")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我今天有一个不太有趣的问题.
这是首选的方式:

Hi all,
I have a less interesting question today.
What is the preferred way to go, this one:

String.IsNullOrEmpty("");


或这个:


or this one:

string.IsNullOrEmpty("");



我已经在不同的代码示例中看到了这两种方式(在MSDN中,它们似乎也有所不同).

那么首选的方式是什么?

并请客气并解释为什么您选择e方法而不是另一种方法.

非常感谢,祝您有美好的一天
安迪


PS,我知道关键字/别名是其类型的同义词:)



I have seen both ways in different code amples (also in MSDN they seem to vary).

So what is the preferred way to go?

And please be so kind and explain why you choose on e method over the other one.

Thanks a lot and have a great day
Andy


PS, I know that keywords/aliases are synonyms for their types :)

推荐答案

您已经知道string是System.String的别名,因此可以使用其中任何一个,但是我认为string.IsNullOrEmpty看起来很奇怪.

引用对象时,我总是使用字符串.
示例:

As you already know string is a alias for System.String so it is ok to use any of them, but I think string.IsNullOrEmpty looks strange.

I always use string when referring to an object.
Example:

string firstname = "Mike";
string message = String.Format("Hello {0}!", firstname);


string是System.String的别名,例如int是System.Int32的别名,所以这实际上没有关系.

如果使用int扩展名,该怎么办?

string is an alias for System.String like int is alias for System.Int32 so it really doesn''t matter.

What do you use if you use int extensions?

var test = "123";
var myInt1 = Int32.Parse(test);
var myInt2 = int.Parse(test);



相同的东西.



same thing..


String string 恰好意味着C#中的相同的东西.

如您在问题string中所述,>的别名System.String.

看来惯例是在引用对象时使用string ,而在专门引用 string类时使用String .

您可以在代码中互换使用它们.
String and string mean exactly the same thing in C#.

As you stated in your question string, is an alias for String for System.String.

It seems that the convention is to use string when you are referring to an object and String when you are referring specifically to the string class.

You can use them interchangeably in your code.
String x = string.Copy ("x");
string y = String.Copy ("y");



使用字符串"专门引用String类.
引用String类的对象时,请使用字符串".
引自此处 [ String.IsNullOrEmpty [



Use "String" to refer specifically to the String class.
Use "string" when referring to an object of the String class.
Referred from here[^]

Look at good article on CP:
More detailed explanation about String.IsNullOrEmpty[^]


这篇关于String.IsNullOrEmpty(“")或string.IsNullOrEmpty(“")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆