foreach w/ custom class

Results 1 to 2 of 2

Thread: foreach w/ custom class

  1. #1
    Join Date
    Dec 1969

    Default foreach w/ custom class

    If I had 2 classes and wanted to use them like this:<BR>class2 foo;<BR>foreach(class1 x in foo)<BR>{}<BR>what would the definition of class2 look like?

  2. #2
    Join Date
    Dec 1969

    Default RE: foreach w/ custom class

    class2 must implement IEnumerable.<BR><BR><BR ><BR>Which basically means that it has to have a GetEnumerator method.<BR><BR>And that method has to return an instance of yet another class that must support the IEnumerator interface.<BR><BR><BR ><BR>And that class has to supply a Current property as well as MoveNext and Reset methods.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts