Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.IsNullOrEmpty or string.IsNullOrEmpty [duplicate]

I have been looking through code for the last 3 days, and the original developer is defining Strings using the String class rather than the string class. So, when they've used the IsNullOrEmpty method, it's defined String.IsNullOrEmpty.

What I'd like to know is how is the compiler dealing with String.IsNullOrEmpty compared to string.IsNullOrEmpty?

Is there any advantages using String.IsNullOrEmpty over string.IsNullOrEmpty?

like image 324
Neil Knight Avatar asked Mar 09 '10 10:03

Neil Knight


People also ask

Should I use IsNullOrEmpty or IsNullOrWhiteSpace?

The method IsNullOrWhiteSpace covers IsNullOrEmpty , but it also returns true if the string contains only white space characters. So its always better to use IsNullOrWhiteSpace than IsNullOrEmpty ?

What is the meaning of string IsNullOrEmpty?

In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String. Empty (A constant for empty strings).

What is better string empty or?

Empty will serve you better than using “”. In the cases where String. Empty will not work either because of the code evaluation OR because of the performance considerations, yes, use “” instead. But, do it because there is a supportable reason, not because you think it may produce faster code.

Is string null or empty?

An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters. A null string is represented by null .


2 Answers

They are both the same.

string is a keyword alias in c# for System.String.

Only difference is that when using String, you need to use either System.String.IsNullOrEmpty or using System; at the begining of your code file.

like image 132
logicnp Avatar answered Oct 12 '22 11:10

logicnp


String stands for System.String and it is a .NET Framework type. string is an alias in the C# language for System.String. Both of them are compiled to System.String in IL (Intermediate Language), so there is no difference. Choose what you like and use that. If you code in C#, I'd prefer string as it's a C# type alias and well-know by C# programmers.

I can say the same about (int, System.Int32) etc..

like image 37
šljaker Avatar answered Oct 12 '22 09:10

šljaker