using foreach

  • Thread starter Thread starter tony
  • Start date Start date
T

tony

Hello!!

If I have this for loop construction can this be rerwritten to use foreach
instead.
How is that written?

for ( int i = 0; i < dsMspElYield.Tables[0].Rows.Count; i++ )
arrayList.Add( dsMspElYield.Tables[0].Rows["ELYIELD_NAME"] );


//Tony
 
Tony,

You would do it like this:

foreach (DataRow row in dsMspElYield.Tables[0].Rows)
{
arrayList.Add(row["ELYIELD_NAME"]);
}

Hope this helps.
 
tony said:
Hello!!

If I have this for loop construction can this be rerwritten to use foreach
instead.
How is that written?

for ( int i = 0; i < dsMspElYield.Tables[0].Rows.Count; i++ )
arrayList.Add( dsMspElYield.Tables[0].Rows["ELYIELD_NAME"] );


Try:

foreach (DataRow row in dsMspElYild.Tables[0])
{
arrayList.Add(row["ELYIELD_NAME"]);
}
 
Hi,
foreach (DataRow row in dsMspElYild.Tables[0])
{
arrayList.Add(row["ELYIELD_NAME"]);
}

You need to specify .Rows , DataTable has not a default indexer, DataView
does though.
 
foreach (DataRow row in dsMspElYild.Tables[0])
{
arrayList.Add(row["ELYIELD_NAME"]);
}

You need to specify .Rows , DataTable has not a default indexer, DataView
does though.

Oddly enough though, if the dataset is strongly typed, it will support
IEnumerable.

-- Barry
 
Ignacio said:
Hi,
foreach (DataRow row in dsMspElYild.Tables[0])
{
arrayList.Add(row["ELYIELD_NAME"]);
}

You need to specify .Rows , DataTable has not a default indexer, DataView
does though.

My bad. Was too fast to type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top