列出里面的类

时间:2016-03-06 12:30:35

标签: c# .net

主类:

public class ServiceResponse
{  
    public string RequestId { get; set; } 
    public string ConnectionId { get; set; }    
    public List<FTTask> Tasks { get; set; }        
}

列表类:

public class FTTask
{
    public int TransType { get; set; }
    public int Status { get; set; }
    public string TaskStatus { get; set; }
}

ServiceResponse sr;   // class object
int count = _SerResponse.Tasks.Count;      // count list items

如何在for循环中找到此列表类的每个参数值...

for (int j = 0; j < count; j++){
       //     Unable to find TransType,status values of list inside this loop
}

4 个答案:

答案 0 :(得分:0)

using System.Reflection;

PropertyInfo[] props = typeof(Item).GetProperties();
for(int i = 0; i < props.Length; i++)
{
    string ParamName = props[i].Name;
}

答案 1 :(得分:0)

您需要获取对列表项的引用。

for (int j = 0; j < count; j++){
     FTTask task = _SerResponse.Tasks[j]
       //     Unable to find TransType,status values of list inside this loop

}

答案 2 :(得分:0)

可能是简单的

ServiceResponse rep = // instance of this class

for (int j = 0; j < rep.Tasks.Count ; j++){
     FTTask ftTask = rep.Tasks[j];
     int transTypeValue = ftTask.TransType;
}

答案 3 :(得分:0)

我认为你走在正确的轨道上。请参阅下面的脚本添加内容。希望这会有所帮助。

for (int j = 0; j < count; j++){
           //     Unable to find TransType,status values of list inside this loop
           FTTask fTTaskEntry = _SerResponse.Tasks[j];
           int transType = fTTaskEntry.TransType; //<- this is it right?
    }