The following shows MyEmpty, which is “” while I thought it would be null.
public class SomeClass
{
public static readonly String MyEmpty;
...
}
If MyEmpty is “” rather than null, does it have to be going like this below?
public class SomeClass
{
public static readonly String MyEmpty = "";
...
}
Somehow the ‘readonly’ makes that happen but why?
Thanks in advance.
[Edit]
I was testing these two using MessageBox.Show() assuming that the method would throw an exception when I give it a null value. But it didn’t throw any exception at all, which is why I thought that in my first code MyEmpty was not null but “”.
Thank you all for trying to explain the difference between null and “” and also my mistake.
With your first code MyEmpty should be null.
you specified the “readonly” keyword so i guess the only place you changed it’s value to “” is in the constructor.
The reason that you can’t get “” without specifying it is that the empty string “” needs to be allocated (unless you reference string.empty) so it can’t be that you get that value by default