public class A
{
public long TestCaseId { get; set; }
public byte TestCaseNumber { get; set; }
public object FetchList { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<int> a = new List<int>(){ 1, 2, 3, 4 };
List<A> Objectlst = new List<A>();
Objectlst .Add(new A { TestCaseId = 1, TestCaseNumber = 1, FetchList = a });
foreach (var item in Objectlst)
{
Console.WriteLine(item.FetchList);
}
}
}
[类别为A
。如果我要为对象数据类型FetchList
分配通用列表,有人可以告诉我如何通过此属性FetchList
检索存储在列表中的所有值吗?
foreach (var item in Objectlst)
{
var list = item.FetchList as List<int>;
if (list != null)
foreach (int num in list)
Console.WriteLine(num);
}