Thread overview
foreach
Mar 27, 2003
Matthew Wilson
Mar 27, 2003
anderson
Mar 28, 2003
Jon Allen
Mar 27, 2003
Walter
March 27, 2003
Any progress on this. It'd be real nice.

Has the format been decided yet? I would suggest that as well as supporting

char[] s = "Some string";

foreach (c in s)
  c  = c + 2;

it also supports specification of the type of the element, to support conversions

class Y
{
  void DoSomething()
  {
  }
}

class X
{
  int i;
  Y y;

  operator Y() // I don't know what the syntax for user-defined operator
methods is.
}

X[] arr = new X[10];

foreach (Y y in arr)
  y.DoSomething();


Make sense?




March 27, 2003
"Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5ul7c$17q2$1@digitaldaemon.com...
> Any progress on this. It'd be real nice.
>
> Has the format been decided yet? I would suggest that as well as
supporting
>
> char[] s = "Some string";
>
> foreach (c in s)
>   c  = c + 2;
>
> it also supports specification of the type of the element, to support conversions
>
> class Y
> {
>   void DoSomething()
>   {
>   }
> }
>
> class X
> {
>   int i;
>   Y y;
>
>   operator Y() // I don't know what the syntax for user-defined operator
> methods is.
> }
>
> X[] arr = new X[10];
>
> foreach (Y y in arr)
>   y.DoSomething();
>
>
> Make sense?
>
>


Parhaps, foreach could also act like a with startement....

X[] arr = new X[10];

foreach (Y y in arr)
  .DoSomething();

Of course for nested loops the implicit form could be used.


March 27, 2003
I'm going to do foreach, but the syntax is a bit up in the air right now.

"Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5ul7c$17q2$1@digitaldaemon.com...
> Any progress on this. It'd be real nice.
>
> Has the format been decided yet? I would suggest that as well as
supporting
>
> char[] s = "Some string";
>
> foreach (c in s)
>   c  = c + 2;
>
> it also supports specification of the type of the element, to support conversions
>
> class Y
> {
>   void DoSomething()
>   {
>   }
> }
>
> class X
> {
>   int i;
>   Y y;
>
>   operator Y() // I don't know what the syntax for user-defined operator
> methods is.
> }
>
> X[] arr = new X[10];
>
> foreach (Y y in arr)
>   y.DoSomething();
>
>
> Make sense?
>
>
>
>


March 28, 2003

> > foreach (Y y in arr)
> >   y.DoSomething();
> >
> >
> > Make sense?

Sounds yummy to me :-)

> Parhaps, foreach could also act like a with startement....
>
> X[] arr = new X[10];
>
> foreach (Y y in arr)
>   .DoSomething();
>
> Of course for nested loops the implicit form could be used.

Special cases are bad, if we did it for foreach should do it for for too, but we can't really, because the c-style for is much to flexible for anything as straightforward as that.  Not to mention the ugliness of nested loops.  I say we just explicitly write "with" when we want a with.