0

Similar to this: C# Array of Increments I've also looked at this: Getting a sub-array from an existing array

I calculate a sum to achieve my value from a position in my array, for instance I want to decode to a float position 502 in my byte array and increment the position by 2 so I would be looking at position 504, 506, 508 etc. a specified amount of time like 100 times (so 100 values). So I thought using a for loop may be best, please note I can retrieve the first value just need to get the rest. I need to step through and retrieve three different variables, not just the one.

I've seen this around (have never used it) and think the '+= 2' is the steps?

for (int i = 1; i < 100; i += 2) { }

At the moment I have something like (This just gets me the first value, no idea how to increment position)

int of2 = 502;
int of1 = 254;
int of3 = 750;

for (int i = 1; i < 100; i++) 
{
    float f1 =  Decode(Rec, of1) / (float)100;
    float f2 =  Decode(Rec, of2) / (float)100;
    float f3 =  Decode(Rec, of3);
}

The end result should look like:-

Structure

(f1, f2, f3)

(f1, f2, f3)

(f1, f2, f3)

enter image description here

Community
  • 1
  • 1
lornasw93
  • 182
  • 4
  • 26

1 Answers1

0

Hope thats what you want:

int of2 = 502;
int of1 = 254;
int of3 = 750;

for (int i = 1; i < 100; i++) 
{
    float f1 =  Decode(Rec, of1) / (float)100;
    float f2 =  Decode(Rec, of2) / (float)100;
    float f3 =  Decode(Rec, of3);
    of1 +=2;
    of2 +=2;
    of3 +=2;

}
Murdock
  • 4,352
  • 3
  • 34
  • 63
  • This looks good to me, I will try it thanks! Do you know how to, for example, display all values? I'm not too great with loops. Really appreciate it. – lornasw93 Mar 28 '14 at 07:38
  • Well obviously depends on the kind of app. In a console app just put Console.Writeline(string.Format("{0} {1} {2}",of1,of2,of3 )) – Murdock Mar 28 '14 at 09:09