On Thu, 13 Dec 2007 11:07:38 -0800, tshad <ts***@dslextreme.comwrote:
[...]
// Define Collections here
public class TestCollection : List<Test>
************************************
What is this doing here?
I assume that I have a class of Test and the last line allows me to make
class that is just a collection (array) of objects of type Test.
Is that what is happening here?
The last line creates a new class that _inherits_ the List<Testclass.
The List<Testclass itself is a concrete version of the generic List<T>
class, which is not exactly an array. It's sort of a merged version of
Array and ArrayList, with typed elements like an Array has, but with the
dynamic features of ArrayList.
By inheriting it, the TestCollection class can add its own functionality
to the base List<Testbehavior. I would not bother inheriting List<Test>
unless that extension was specifically needed or desired. You might as
well just use List<Testdirectly instead.
I then saw some code that did something like:
...
List<TestmyList:
...
Which would define "myList" as a collection of objects of type Test?
Yes. It declares myList as a specific kind of collection of objects of
type Test. .NET has a wide variety of collection types, and the generic
List<Ttype is just one of them.
Perhaps more important for you to understand is that the "<T>" part is not
unique to collections. The collection classes happen to be one of the
more prominent uses of generics in the framework, but generics are not
used solely for collections. So in that example, it's the "List" part
that is the important thing with respect to the type being a collection;
the "<Test>" part is just part of the way you declare that particular kind
of collection (that is, using a generic class).
Pete