On one hand an ArrayList is flexible, because you can stuff any type
of object into an arraylist for storage. It's getting the object back
out and manipulating the object as a specific type that is indeed
awkward. Some people will try to get rid of the awkwardness by
creating thier own strongly typed container classes (i.e. a class that
would only store Test instances, and only return Test instances), but
this involves additional code. Generics, in .NET 2.0, will make the
process much easier:
http://msdn.microsoft.com/msdnmag/issues/03/09/NET/
--
Scott
http://www.OdeToCode.com/
On Sat, 2 Oct 2004 07:58:35 -0600, "mb" <mm@hotmail.com> wrote:
I guess that will work. It's funny, none of the books I have looked at show
how to do this. In my experience so far, ArrayLists are cumbersome and
awkward. Are they supposed to be like this?
"Stefan Holdermans" <st****@mimmick.nl> wrote in message
news:41**************@mimmick.nl... MB,
MB> If an ArrayList has an object named "myTest" which has properties
MB> ".Name" and ".Number". now how do I change the .Name of the
MB> object in the arraylist?
using System;
using System.Collections;
class Test {
public string Name;
public int Number;
public static void Main() {
Test myTest = new Test() ;
ArrayList myList = new ArrayList();
myList.Add(myTest);
((MyTest) myList[0]).Name = "MB";
((MyTest) myList[0]).Number = 7 ;
Console.Write(myTest.Name) ;
Console.Write(myTest.Number);
}
}
HTH,
Stefan