JB wrote:
Hello
List<Tis said to be more powerful than ArrayLists but if you have
something like this:
List<intmylst = new List<>;
myList.Add("Joe");
myList.Add(25);
the list doesn't seem to accept the name "Joe".
How do you get a List<to accept different datatype if possible?
JB
You use the most specific data type that is common for the data types
that you want to put in the list.
As mentioned in the thread, List<Objectworks the same way as an
ArrayList. If you really need a list of object references, you should
rather use List<Objectthan ArrayList. That way it's clear that you
actually indended to use that kind of list, and not that you just used
an ArrayList because you didn't know better.
In most cases, you should be able to find a common data type that is
more specific than Object. For example if you want to put instances of
System.Windows.Controls.Button and System.Windows.Controls.Label in the
same list, you can use a List<System.Windows.Controls.Control>.
--
Göran Andersson
_____
http://www.guffa.com