Avatar of thomasmutton
thomasmutton
Flag for United Kingdom of Great Britain and Northern Ireland asked on

C# for loop

Hello experts.

I have a for loop that works great but I want the first number to be one instead of zero.

how would I do this?
for (int i = 0; i < ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

Editors IDEsC#ASP.NET

Avatar of undefined
Last Comment
thomasmutton

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
CyrexCore2k

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
oxyoo


for (int i = 1; i <= ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

CyrexCore2k

oxyoo that will execute the loop once less than the number of rows in the table which I don't think he wants.
CyrexCore2k

Oh I see the <=

Instead he'll get an array index out of bounds when he tries ds.Tables["tbl_trainingmodulesquestions"].Rows[i]....
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
oxyoo

sorry, this should work better..


for (int i = 1; i < ds.Tables["tbl_trainingmodulesquestions"].Rows.Count; i++)
{
       i.tostring();
}

Open in new window

oxyoo

Ok, I see your point CyrexCore2k.
thomasmutton

ASKER
Brilliant. Thanks alot.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.