In C#, Is null, "", and string.Empty the exact same thing described 3 different ways?

Is null, "" and string.Empty the exact same thing?  Please explain your answer.

CommonHelpers.LastWorkingProjectID == null || CommonHelpers.LastWorkingProjectID == "" || CommonHelpers.LastWorkingProjectID == string.Empty

Open in new window

LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan Violet SagmillerCIS/Game Development AdvisorCommented:
A string is an object, and so it is passed around by pointers to the memory where it actually exists.  

Null means the pointer points to nothing, that the string doesn't reference any memory.  I.e. string b = null; var a = b.Length; throws an exception.  Since b is null, there are no methods that work off of it.

prior to .Net 2.0, there was a difference between .Empty and "", but now they operate the same.
0
Chris StanyonWebDevCommented:
Null means Nothing. It doesn't exist. There is no such thing. String.Empty and "" means that it does exist. There is an Object in memory. It has a value, albeit an empty, zero-length value.

With an empty string, your variable will exist as an Object in memory, so you can call any of the normal string members on it: myVar.Length, myVar.ToUpper()

When it's set to Null, there is no object, so trying to call any members will give you a Null Reference Exception.

Your statement can be simplified to:

string.IsNullOrEmpty(CommonHelpers.LastWorkingProjectID)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Thank you... this was very helpful.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.