Switch case and generics checking

后端 未结 7 720
情话喂你
情话喂你 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;
    }
    
    0 讨论(0)
提交回复
热议问题