Re: IEnumerator in a Struct

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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);
}
}
}
.



Relevant Pages

  • Re: INT() vs CInt()
    ... >> will yield different results. ... CInt and Int are not different names for similar functions. ... > mathematical truncating function. ... "conversion function that also rounds while converting." ...
    (microsoft.public.vb.general.discussion)
  • Re: Return statement twice in the same expression
    ... > int main{ ... > This code yields a compilation error, ... All expressions involved in the ternary operator must yield a value. ... It can be used as a control structure. ...
    (comp.lang.c)
  • Re: Plauger, size_t and ptrdiff_t
    ... Plauger's "The Standard C Library," where he states "... ... This language would not rule out one being int ... operator can only yield values from 0 to 65535, ...
    (comp.lang.c)
  • Re: INT() vs CInt()
    ... >>> will yield different results. ... CInt and Int are not different names for similar functions. ... CInt is a conversion function and Int is ... Well, if your numbers are all positive, then Int is a "truncating ...
    (microsoft.public.vb.general.discussion)
  • Re: Where do pointers point to?
    ... > yield an lvalue ... yea, my bad, but that was not what the question was all about ... void memset2(void *p, int c, int n) ...
    (comp.lang.c)