Results 1 to 2 of 2

Thread: Dynamically building statements

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    94

    Dynamically building statements

    Hi guys,

    How can I rewrite this so that it is dynamic? That is, I want there to be a variable number of elements with the q# entries going from 1 to #...

    decimal[] vals = new decimal[7];
    vals[0] = Convert.ToDecimal (context.Request["q1"]);
    vals[1] = Convert.ToDecimal (context.Request["q2"]);
    vals[2] = Convert.ToDecimal (context.Request["q3"]);
    vals[3] = Convert.ToDecimal (context.Request["q4"]);
    vals[4] = Convert.ToDecimal (context.Request["q5"]);
    vals[5] = Convert.ToDecimal (context.Request["q6"]);
    vals[6] = Convert.ToDecimal (context.Request["q7"]);

    Thanx in advance!

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    int desiredNumber = 7;
    decimal[] vals = new decimal[desiredNumber];

    for (int i = 0; i < desiredNumber; i++) {
    vals[0] = Convert.ToDecimal (context.Request["q" + desiredNumber.ToString()]);
    }
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width