Switch case and generics checking

后端 未结 7 722
情话喂你
情话喂你 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:20

    You might use TypeCode for switch:

    switch (Type.GetTypeCode(typeof(T)))
    {
        case TypeCode.Int32:
           break;
        case TypeCode.Decimal:
           break;
    }
    

提交回复
热议问题