Click to See Complete Forum and Search --> : [RESOLVED] String.empty v.s. string.null
George2
June 19th, 2008, 08:39 AM
Hello everyone,
I am doing input parameter checking for a string type, and string value except empty is valid. My function is provided to outer client to call. Sometimes I find to check null is not enough, I also need to check String.Empty.
My question is, what are the differences between null and String.Empty? I have made some web search for the answers but not very useful information.
thanks in advance,
George
PaulMdx
June 19th, 2008, 08:59 AM
Null means the variable has no reference set
String.Empty means the variable references a string with no characters, eg ""
STLDude
June 19th, 2008, 09:58 AM
To be sure use String.IsNullOrEmpty (http://msdn.microsoft.com/en-us/library/system.string.isnullorempty(VS.80).aspx).
boudino
June 20th, 2008, 01:28 AM
Definitely, at least until there is semantic difference between nothing and empy in your application (e.g. null means never filled, empty means set by user to be empty).
The difference is exactly as PaulMdx has said.
cjard
June 20th, 2008, 02:49 AM
George, do you not feel that this question is a little too inane? Going from asking about advanced topics such as Asyncronous IO, to what the difference is between a null and non-null value borders on trolling.
Asserting you cannot find any information about the significance of "null" in .net (or programming in general) with google is absolute nonsense - my google for string.empty vs null turned up 874,000 hits and I note that 10 of them on the first few pages were your question here, crossposted to different forums.
If it's gotten to the stage where so many people are tired of your questions that you have to post to 10 different forums just to get a response, I think you need to take a look at how you conduct yourself online; youre all take and no give and communities like this wouldnt work if everyone was like you.
Keep it up and you'll earn yourself a temporary ban with a strong view to it becoming permanent. Consider this a final, formal, written warning.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.