高手帮忙,怎么实现IEnumeratable<T>接口?
提示: 作者被禁止或删除 内容自动屏蔽
public class student : IEnumerable<string> { private string no; private string name; private string sex; private string hobby; public student() { no = "20010"; name = "baomi"; sex = "male"; hobby = "computer game"; } public string this[string item] { get { switch (item) { case "no": return no; case "name": return name; case "sex": return sex; case "hobby": return hobby; default: return "bad indexing"; } } } public IEnumerator<string> GetEnumerator() { yield return "no"; yield return "name"; yield return "sex"; yield return "hobby"; } IEnumerator IEnumerable.GetEnumerator() { return (this as IEnumerable<string>).GetEnumerator(); } }