Ok so I was just working through the IEnumerator
and IEnumerable
. Now the MSDN says that the main objective of these things is to iterate through a customer collection.
Fair enough I was however able to iterate through a custom collection without the use of either (or at least I'd like to think so)
namespace ienumerator
{
class person
{
public person(string first, string second)
{
fname = first;
lname = second;
}
public string fname { get; set; }
public string lname { get; set; }
}
class person_list
{
public person[] list;
public person_list(person[] per)
{
list = new person[per.Length];
for (int i = 0; i < per.Length; i++)
{
list[i] = per[i];
}
}
}
class Program
{
static void Main(string[] args)
{
person[] names = new person[3]
{
new person("some","one"),
new person("another","one"),
new person("sss","ssdad"),
};
person_list list_of_names = new person_list(names);
int i = 0;
while (i < list_of_names.list.Length)
{
Console.WriteLine(list_of_names.list[i].fname);
i++;
}
Console.Read();
}
}
}
So what is flawed in my understanding, the above is giving me the same result that I achieve after implementing IEnumerator
and IEnumerable
.
LinkedList
and try to compile it. – Ecclesint i
is a simple (and exposed) iterator. – Asphyxiate