473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using foreach

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
5 7325
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christian Decker | last post by:
I wanted to know if is a good idea to create classes that mirror exactly the structure of a database. This might sound a bit fuzzy but I'l explain myself with an example: CREATE TABLE...
11
by: Benny | last post by:
I just wanted to throw the discussion out there on what the best practice people feel is for using large objects in a foreach loop. For example if you are reusing an Image object in a loop like...
13
by: inpuarg | last post by:
Is it possible to get all controls and all of their children on a Windows form without using recursive methods ?
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
1
by: Doug | last post by:
Hi, I have a collection of objects and I need to compare each item in the collection to see if it's a match on any or all of the others. I have stored my collection in an item like so: ...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
6
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. Now If I want to implement functionallity so I can compare animal with each other or...
5
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= | last post by:
Can someone help me convert this to the latest C# syntax using predicate/delegate? You can see my attempt in the comments. Also: how would I set a new font for q_ul? q_ul is a WPF TextBlock and I...
28
by: natarajmtech | last post by:
Hi all, I have defined some array variables a ***************************************** @L=('CTT','CTC','CTA','CTG','TTA','TTG'); @S=('TCT','TCC','TCA','TCG','AGT','AGC'); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.