C# Loop 5 times

Posted on 2006-04-12
Last Modified: 2010-04-16
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
Question by:sbornstein2
    LVL 11

    Accepted Solution

    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)]
    LVL 6

    Expert Comment

    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?
    LVL 6

    Expert Comment

    oop... Expert beat me to the punch! =)

    Author Comment

    thanks guys

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now