Ajax3.14 Ajax3.14 -3 years ago 110
C# Question

How to set the value of string to null

I am aware that I can set null like

string val = null;

But I am wondering the other ways I can set it to null. Is there a funcion like
that I can use.

Answer Source

I think you are looking far String.Empty

string val = String.Empty;

Update: TheFuzzyGiggler comments are worth mentioning:

It's much better to set a string to empty rather than null. To avoid exceptions later. If you have to read and write a lot of strings you'll have null value exceptions all over the place. Or you'll have a ton of if(!string.isNullorEmpty(string)) which get annoying

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download