如果对象是泛型列表 [英] If object is Generic List

查看:144
本文介绍了如果对象是泛型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法来确定一个对象是一个通用的列表?我不会知道列表的类型,我只知道这是一个列表。我该如何确定?

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?

推荐答案

这将返回True

List<int> myList = new List<int>();

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

你关心知道,如果这正是一个清单......或者,你确定它是IEnumerable的,和一般?

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

这篇关于如果对象是泛型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆