How to use trim for c#.net when its null

How to use trim for c#.net when its null ?

More body will tell you that

//============================

string txt=null;

string mystring="";

if(txt!=null){
  mystring=txt.Trim();
}

//============================

OK,you know,some times we have more string need to check when form submit . This is too tired .

We all need a easy way for us . let me show it .

//============================

string txt=null;

string mystring="";

mystring=(txt??"").Trim();

//============================

Well ! That's end . So easy . Go to try it gay !

You need not overwrite System.String , and it is sealed .

 

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注