D
Dan
Given some object that I define as:
class myItem
{
public string szItemName = "";
public string szItemValue = "";
public string szOrderNumber = ""
}
that is collected into an ArrayList
ArrayList aryItems = new ArrayList();
// code to populate aryItems here
Now say I go through the array with a "foreach" loop, and change some
values, do I need to do the following?
foreach ( myItem itm in aryItems )
{
if ( itm.szItemName == "fred" )
{
// first remove the element from the array
int nIndex = aryItems.IndexOf ( itm );
aryItems.Remove (itm);
// now change the object in some way
itm.szItemValue = "flintstone";
// reinsert the object back into the array
aryItems.InsertAt ( itm )
}
}
or can I do this?
foreach ( myItem itm in aryItems )
{
if ( itm.szItemName == "fred" )
{
// just change the object in some way, this
// updates the object in stored in the collection as well...
itm.szItemValue = "flintstone";
}
}
Basically in the foreach enumeration is each object being copied to another
object that I reference, or does it provide a point back to the object
existing in the collection...
class myItem
{
public string szItemName = "";
public string szItemValue = "";
public string szOrderNumber = ""
}
that is collected into an ArrayList
ArrayList aryItems = new ArrayList();
// code to populate aryItems here
Now say I go through the array with a "foreach" loop, and change some
values, do I need to do the following?
foreach ( myItem itm in aryItems )
{
if ( itm.szItemName == "fred" )
{
// first remove the element from the array
int nIndex = aryItems.IndexOf ( itm );
aryItems.Remove (itm);
// now change the object in some way
itm.szItemValue = "flintstone";
// reinsert the object back into the array
aryItems.InsertAt ( itm )
}
}
or can I do this?
foreach ( myItem itm in aryItems )
{
if ( itm.szItemName == "fred" )
{
// just change the object in some way, this
// updates the object in stored in the collection as well...
itm.szItemValue = "flintstone";
}
}
Basically in the foreach enumeration is each object being copied to another
object that I reference, or does it provide a point back to the object
existing in the collection...