c# - Negate the null-coalescing operator -


I have a bunch of strings that I have to use on trim, but they can be zero. It would be too short if I could do something like this:

  string endString = startString!? StartString.Trim ();  

Basically return to the right, if the portion on the left is not zero, otherwise return the zero value. I had just finished using the Treneri Operator, but is this the purpose for using blank collage operator?

You can create an extension method that returns null when the value Tries to trim.

  public string trimfnotnational (this string item) {if (String IsNullOrEmpty (item)) return item; Return items again. Rim (); }  

Note that you can not trim its name because the extension methods can not override the example methods.


Comments