C# in VS2005: what is the best way to check if a string is empty?

There's the builtin String. IsNullOrEmpty which I'd use. It's described here.

1 +1 for String instead of string. Similarly to Int32. TryParse instead of int.

TryParse – abatishchev Jun 29 '10 at 9:09 3 @abatishchev: Note that there is no semantical difference between those two. Jon Skeet explained quite well when it makes sense to use each of the variants: stackoverflow.com/questions/215255/strin...…. In fact, the C# spec states: "As a matter of style, use of the keyword is favored over use of the complete system type name." – 0xA3 Jun 29 '10 at 9:13 @0xA3: Undoubtedly.

For me, first of all, this is just style of code – abatishchev Jun 29 '10 at 9:33.

Try this one: if (string. IsNullOrEmpty(YourStringVariable)) { //TO Do }.

As suggested above you can use String. IsNullOrEmpty, but that will not work if you also want to check for strings with only spaces (some users place a space when a field is required). In that case you can use: if(String.

IsNullOrEmpty(str) || str.Trim(). Length == 0) { // String was empty or whitespaced }.

C# 4 has the String. IsNullOrWhiteSpace() method which will handle cases where your string is made up of whitespace ony.

1 ... which doesn't matter since it was asked for VS2005, i.e. . NET 2.0.

Would have been a great comment though. – OregonGhost Jun 29 '10 at 9:25.

The string.IsNullOrEmpty() method on the string class itself. You could use string. Length == 0 but that will except if the string is null.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions