c# – swap foreach for for


I need to replace the following foreach() with a for() . The problem is that instead of arrays, the loop goes through a dictionary. This is the code I want to transform a for() :

foreach (var joint in body.Joints.Values)  //transformar em um for para usar valoren anteriores
  eixoX = joint.Position.X.ToString();
  eixoX = eixoX.Replace(",", ".");
  line.Append(eixoX + ",");

  eixoY = joint.Position.Y.ToString();
  eixoY = eixoY.Replace(",", ".");
  line.Append(eixoY + ",");

Not mastering C# I was confused to do this.

Link to class implementations.


Do you want something like that?

for (int index = 0; index < body.Joints.Count; index++) {
  var item = body.Joints.ElementAt(index);
  var jointType = item.Key;
  var joint = item.Value;
Scroll to Top