好吧......如果你想要的只是让某人“让这个该死的东西可枚举”,那就去......
public class ProfilePics : System.Collections.IEnumerable
{
public string status { get; set; }
public string filename { get; set; }
public bool mainpic { get; set; }
public string fullurl { get; set; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
yield break;
}
}
它不枚举任何东西,但它是可枚举的。
现在我将尝试进行一些读心术,并想知道您是否想要这样的东西:
public class ProfilePicture
{
public string Filename { get; set; }
}
public class ProfilePics : IEnumerable<ProfilePicture>
{
public List<ProfilePicture> Pictures = new List<ProfilePictures>();
public IEnumerator<ProfilePicture> GetEnumerator()
{
foreach (var pic in Pictures)
yield return pic;
// or simply "return Pictures.GetEnumerator();" but the above should
// hopefully be clearer
}
}