C# Extension Method for String Data Type

后端 未结 7 1885
清酒与你
清酒与你 2020-12-11 10:58

My web application deals with strings that need to be converted to numbers a lot - users often put commas, units (like cm, m, g, kg) and currency symbols in these fields so

7条回答
  •  清歌不尽
    2020-12-11 12:00

    Just answering the how do I create extension method for string class:

    public static class MyStringExtensions {
    public static ToDecimal(this string input) {
       // ...
    }
    }
    

    (and you need to have an using statement for the namespace it is located in order to use it)

提交回复
热议问题