C# question

Can somebody explain to me what is the different betwen the following statement please:

userName != "" || userName !=string.Empty

It seems to me they are tesing for the same condition in both.
Who is Participating?
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.

Both are same :)
They are very close to being the same. In practice, the difference is negligible.  If you want an in-depth view of how things are the way they are with String.Empty, see this extensive answer of me about a month ago: http://www.experts-exchange.com/Q_24315307.html#24126618

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
bottom line is: your method is good, use String.Empty for clearer code (or String.IsNullOrEmpty(yourString), which also tests for null), but opinions vary on whether it really is clearer. Use never ever the code "userName Is String.Empty", which is not the same and may yield unexpected results (see earlier link on why that is).
Well, it looks like you've got your answer; however, I think abel got confused with his "username Is String.Empty" reference. This is just illegal syntax in C#; it won't return any results at all. The "is" operator (not "Is") is used for checking types, not references or values.

It is arguable as to which one to use (just use one, though). When you make your choice, though, keep it consistent. I would probably recommend String.Empty, as there is less room for error (what if you accidentally plugged in a letter between the quotes for ""?).
> I think abel got confused with his "username Is String.Empty" reference

aha, yes, you are right, thanks for pointing that out. I got mixed up with the referring thread I sent, where VB was used  instead of C# and where "Is" can be used for checking reference-identity. The thing being, that it will only return true in VB when both sides are Interned, but that's another discussion.

tx for the grade ube100 ;-)
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

From novice to tech pro — start learning today.