If object is Generic List

前端 未结 6 462
既然无缘
既然无缘 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 11:06

    This will return "True"

    List myList = new List();
    
    Console.Write(myList.GetType().IsGenericType && myList is IEnumerable);
    

    Do you care to know if it's exactly a "List"... or are you ok with it being IEnumerable, and Generic?

提交回复
热议问题