Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have a less interesting question today.
What is the preferred way to go, this one:
C#
String.IsNullOrEmpty("");

or this one:
C#
string.IsNullOrEmpty("");


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 :)
Posted
Updated 16-Jul-12 3:21am
v3
Comments
hoernchenmeister 17-Jul-12 3:11am    
Thanks to all who contributed to my question.
Have a great day
Andy
Prasad_Kulkarni 17-Jul-12 3:31am    
You're welcome!
Glad it helps..

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:

C#
string firstname = "Mike";
string message = String.Format("Hello {0}!", firstname);
 
Share this answer
 
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?

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


same thing..
 
Share this answer
 
v3
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.
C#
String x = string.Copy ("x");
string y = String.Copy ("y");


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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900