2014-12-03 365 views
0

我不明白我是如何解決這個問題的。我有兩個foreach循環:不明白」不包含「GetEnumerator」的公共定義「」「

foreach (deviceDetailsModel.Detail d in ddm.device.details) 
{ 
    foreach (deviceDetailsModel.Entry e in d) 
    { 
     //TODO 
    } 
} 

二號for循環,我得到了does not contain a public definition for 'GetEnumerator'錯誤。我究竟做錯了什麼?

這是類:

public class deviceDetailsModel 
{ 
    public int totalCount { get; set; } 
    public string messages { get; set; } 
    public Device device { get; set; } 

    public class Entry 
    { 
     public string key { get; set; } 
     public object value { get; set; } 
    } 

    public class Detail 
    { 
     public List<Entry> entry { get; set; } 
    } 

    public class Device 
    { 
     public string @id { get; set; } 
     public string uuid { get; set; } 
     public string principal { get; set; } 
     public int blockReason { get; set; } 
     public int clientId { get; set; } 
     public string comment { get; set; } 
     public int compliance { get; set; } 
     public int countryCode { get; set; } 
     public int countryId { get; set; } 
     public string countryName { get; set; } 
     public string createdAt { get; set; } 
     public string currentPhoneNumber { get; set; } 
     public List<Detail> details { get; set; } 
    } 
} 

回答

9

我想你的意思是:

deviceDetailsModel.Entry e in d.entry 

代替。

由於d(大概是Detail類的一個實例)未實現IEnumerable,所以出現錯誤。您可能想要枚舉entry屬性。

相關問題