Switch case and generics checking

后端 未结 7 721
情话喂你
情话喂你 2021-01-01 10:36

I want to write a function that format int and decimal differently into string

I have this code:

and I want to rewrite it to generi

7条回答
  •  离开以前
    2021-01-01 11:17

    You could instead of using generics use IConvertible

        public static string FormatWithCommaSeperator(IConvertible value)
        {
                IConvertible convertable = value as IConvertible;
                if(value is int)
                {
                    int iValue = convertable.ToInt32(null);
                    //Return with format.
                }
                .....
        }
    

提交回复
热议问题