looking for c# equivalent to c++ vector

Malfunction

Well-known member
Joined
Dec 8, 2003
Messages
203
Location
Berlin, Germany
I was using several ArrayLists to store objects of the same type.
Now Id like to use a typed ArrayList instead of the standard ArrayList which only return "objects" and requires further typecasting.
In c++ Id use the vector template hows it done in c#?
 
Currently you would have to inherit from something like CollectionBase and roll your own collection class.
However in the next version of the framework a new feature called Generics will be present they behave similar to templates in C++.

e.g.
C#:
//Will only work of Framework 2.0 or better not 1.0 or 1.1

    public class Test
    {
        int i, j, k;
       string Hello;
    }

    //generates a strongly type collection for Test objects
    public class TestList : System.Collections.Generic.List<Test>
    {

    }
 //this will allow you to write code elsewhere like
        TestList tl = new TestList();
        tl.Add(new Test());
 
Back
Top