How to extend C# built-in types, like String?

前端 未结 5 1818
别那么骄傲
别那么骄傲 2020-11-28 23:13

Greetings everyone... I need to Trim a String. But I want to remove all the repeated blank spaces within the String itself, not only at the end or

5条回答
  •  [愿得一人]
    2020-11-28 23:42

    Besides using extension methods -- likely a good candidate here -- it is also possible to "wrap" an object (e.g. "object composition"). As long as the wrapped form contains no more information than the thing being wrapped then the wrapped item may be cleanly passed through implicit or explicit conversions with no loss of information: just a change of type/interface.

    Happy coding.

提交回复
热议问题