If object is Generic List

前端 未结 6 445
既然无缘
既然无缘 2021-01-11 10:32

Is there any way to determine if an object is a generic list? I\'m not going to know the type of the list, I just know it\'s a list. How can I determine that?

6条回答
  •  耶瑟儿~
    2021-01-11 10:50

    Try:

    if(yourList.GetType().IsGenericType)
    {
      var genericTypeParams = yourList.GetType().GetGenericArguments;
      //do something interesting with the types..
    }
    

提交回复
热议问题