I'm looking at some code that goes a bit like this:
class Foo { public int Frob; public int Frib; }
class Bar { public Foo Left; public Foo Right; }
public void ProcessBars(Bar[] bars)
{
this.LeftFrobs = new int[bars.Count];
this.RightFrobs = new int[bars.Count];
this.LeftFribs = new int[bars.Count];
this.RightFribs = new int[bars.Count];
//... you get the idea
int counter = 0;
foreach(Bar bar in bars)
{
LeftFrobs[counter] = bar.Left.Frob;
LeftFribs[counter] = bar.Left.Frib;
//...27 more lines of similar
if(bar.Left.Frob == MAGICNUM_A) LeftFribs[counter] = MAGICNUM_B;
RightFrobs[counter] = bar.Right.Frob;
RightFribs[counter] = bar.Right.Frib;
//...27 more lines of similar
if(bar.Right.Frob == MAGICNUM_C) LeftFribs[counter] = MAGICNUM_D;
counter++;
}
}
Aesthetically, this bothers me, but so far, I haven't managed to come up with anything better.
Foo
andBar
have more properties? How exactly do you use the arrays after you create them? I mean, why do you need an array for each combination? \$\endgroup\$Left
andRight
ofData { Frobs, Fribs }
... \$\endgroup\$