Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

C# Loop 5 times

I want to loop 5 times and start with 1 through 5,  I am then going to use [i] appending to a field such as:

for loop 5 times
dvTable.Rows[1]["QTY"] but I want to say QTY[i] so it is QTY1 through QTY5.  How can I do that easily.  Thanks all
0
sbornstein2
Asked:
sbornstein2
  • 2
1 Solution
 
Expert1701Commented:
Here are a few ways to do it:

  for(int i = 1; i <=5; i++)

    dvTable.Rows[1]["QTY" + Convert.ToString(i)]

    dvTable.Rows[1]["QTY" + i.ToString()]

    dvTable.Rows[1][String.Format("{0:0}QTY", i)]
0
 
PoeticAudioCommented:
something like...

for(int i = 1; i <= 5; i++)
{
    dvTables.Rows[1]["QTY" + i.ToString()] = whatever;
}


is this what you mean? or am I not following you?
0
 
PoeticAudioCommented:
oop... Expert beat me to the punch! =)
0
 
sbornstein2Author Commented:
thanks guys
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now