-2

I am confused with below code. Which one is better to use. Can you explain the differences between them.

I am C# learner...

  • string ss = "";
  • string ss = string.Empty;
  • string = null;
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
Happy
  • 323
  • 1
  • 3
  • 12

1 Answers1

4
  1. "" and String.Empty are synonyms. They both refer to an empty string. Which one to use is a matter of preference. The following question contains various opinions on that topic:

    In C#, should I use string.Empty or String.Empty or "" to intitialize a string?

  2. null refers to a null reference. The difference between an empty string and a null reference is detailed in the following question:

    string.Empty vs null.Which one do you use?

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519