G
george r smith
I am trying to create an arrayList that contains multiple arrayLists.
My code attempt is below. The question I have is how can I get away
from creating another pAttribute list than can be added to pItem.
As I understand it (and I coded it to test) if I try to use pAttribute again
by clearing with pAttribute.Clear because it is a shallow copy the
pItem[0] is also cleared. I guess I need a "deep copy" but can't find
any documentation on it.
So is there any way to pItem[1].Add({100.00,200.00}). This will not compile
but
it shows what I want to do.
I might add that I want to use ArrayList because you are not restricted to
one type
as in arrays.
thanks
grs
static void Main(string[] args)
{
ArrayList pItem = new ArrayList();
ArrayList pAttribute = new ArrayList();
for (int i = 101; i < 105; i++)
{
pAttribute.Add(i);
}
pItem.Add(pAttribute);
PrintValues((ArrayList)pItem[0]);
}
public static void PrintValues(ArrayList myList)
{
IEnumerator myEnumerator = myList.GetEnumerator();
while (myEnumerator.MoveNext())
Console.WriteLine(myEnumerator.Current);
}
}
My code attempt is below. The question I have is how can I get away
from creating another pAttribute list than can be added to pItem.
As I understand it (and I coded it to test) if I try to use pAttribute again
by clearing with pAttribute.Clear because it is a shallow copy the
pItem[0] is also cleared. I guess I need a "deep copy" but can't find
any documentation on it.
So is there any way to pItem[1].Add({100.00,200.00}). This will not compile
but
it shows what I want to do.
I might add that I want to use ArrayList because you are not restricted to
one type
as in arrays.
thanks
grs
static void Main(string[] args)
{
ArrayList pItem = new ArrayList();
ArrayList pAttribute = new ArrayList();
for (int i = 101; i < 105; i++)
{
pAttribute.Add(i);
}
pItem.Add(pAttribute);
PrintValues((ArrayList)pItem[0]);
}
public static void PrintValues(ArrayList myList)
{
IEnumerator myEnumerator = myList.GetEnumerator();
while (myEnumerator.MoveNext())
Console.WriteLine(myEnumerator.Current);
}
}