不理解“不包含'GetEnumerator'的公共定义”

本文关键字:定义 GetEnumerator 不包含 不理解 包含 | 更新日期: 2023-09-27 18:33:08

我不明白如何解决这个问题。我有两个foreach循环:

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

不理解“不包含'GetEnumerator'的公共定义”

我想你的意思是:

deviceDetailsModel.Entry e in d.entry

相反。

您收到错误是因为d(可能是 Detail 类的实例)没有实现IEnumerable。您可能希望改为枚举entry属性。