Ajax3.14 Ajax3.14 - 2 years ago 93
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
String.null
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