Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the value of string to null

Tags:

c#

c#-4.0

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.

like image 997
Ajax3.14 Avatar asked Jun 25 '12 17:06

Ajax3.14


1 Answers

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

like image 79
Asif Mushtaq Avatar answered Sep 20 '22 13:09

Asif Mushtaq