Which is better: "for...next" loop or "for each...next" loop?

Showing Answers 1 - 1 of 1 Answers

ravi

  • Jan 3rd, 2007
 

That is Depends on the situation.

for ...next is good in case of performance and it should require index value.

 it varies by the index.

  example:

  for(int i=0;i<10;i++)

    {

           Console.WriteLine(i);

   }

foreach ..next need not index.

it varies by the contents

   example:

    foreach(DataRow r in ds.Tables[0].Rows)

   {

       Console.WriteLine(r["CustId"]);

  }

 abow one is not an exact one, my intension is to saying difference between

for ..next and foreach ..next.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions