Cast generic type parameter to a specific type in C#

后端 未结 7 1024
终归单人心
终归单人心 2021-01-01 17:42

If you need to cast a generic type parameter to a specific type we can cast it to a object and do the casting like below,

void SomeMethod(T t)
{
    SomeClas         


        
7条回答
  •  情歌与酒
    2021-01-01 17:57

    I know this is a late question but here what you can do

    A great option is to make your function accept parameter of class object, and do your switch case as you wish

    And just do the casting

    YourClass = (YourClass) parameterObject;
    

提交回复
热议问题