By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,769 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,769 IT Pros & Developers. It's quick & easy.

using foreach

P: n/a
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[i]["ELYIELD_NAME"] );
//Tony
May 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Tony,

You would do it like this:

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"tony" <jo*****************@telia.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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[i]["ELYIELD_NAME"] );
//Tony

May 16 '06 #2

P: n/a
tony wrote:
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[i]["ELYIELD_NAME"] );


Try:

foreach (DataRow row in dsMspElYild.Tables[0])
{
arrayList.Add(row["ELYIELD_NAME"]);
}
May 16 '06 #3

P: n/a
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.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 16 '06 #4

P: n/a
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
wrote:
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
May 16 '06 #5

P: n/a
Ignacio Machin ( .NET/ C# MVP ) wrote:
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.
May 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.