2016-03-06 15 views
0

主类里面:列表类

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 
} 
+0

'var item = _SerResponse.Tasks [j]' –

回答

0
using System.Reflection; 

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

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

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

} 
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; 
} 
0

我认为我对你track..see我除了下面脚本的权利。希望这可以帮助。

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? 
    }