CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    [RESOLVED] String.empty v.s. string.null

    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

  2. #2
    Join Date
    Feb 2002
    Location
    UK
    Posts
    75

    Re: String.empty v.s. string.null

    Null means the variable has no reference set
    String.Empty means the variable references a string with no characters, eg ""

  3. #3
    Join Date
    May 2007
    Posts
    811

    Re: String.empty v.s. string.null

    To be sure use String.IsNullOrEmpty.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: String.empty v.s. string.null

    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.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: String.empty v.s. string.null

    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.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured