Re: IEnumerator in a Struct
- From: Marc Gravell <marc.gravell@xxxxxxxxx>
- Date: Mon, 10 Mar 2008 09:10:14 -0700 (PDT)
Should be fine (see below). Was there a specific issue you were
seeing?
Marc
using System;
using System.Collections;
using System.Collections.Generic;
struct MyTuple : IEnumerable<int>
{
public readonly int a, b, c, d, e; // lazy... should be props
public MyTuple(int a, int b, int c, int d, int e)
{
this.a = a; this.b = b; this.c = c;
this.d = d; this.e = e;
}
public IEnumerator<int> GetEnumerator()
{
yield return a;
yield return b;
yield return c;
yield return d;
yield return e;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
static class Program
{
static void Main()
{
MyTuple tuple = new MyTuple(1, 2, 3, 4, 5);
foreach(int x in tuple) {
Console.WriteLine(x);
}
}
}
.
- References:
- IEnumerator in a Struct
- From: JPS
- IEnumerator in a Struct
- Prev by Date: Re: Opposite of typeof /GetType()
- Next by Date: Re: IEnumerator in a Struct
- Previous by thread: IEnumerator in a Struct
- Next by thread: Re: IEnumerator in a Struct
- Index(es):
Relevant Pages
|