#835 – A Generic List Can Store Value-Typed or Reference-Typed Objects

You can use a generic list, defined by the List<T> class, to store a dynamically sized collection of objects.  A List<T> can store any type of object, including both value-typed and referenced-typed objects.

            // List of integers
            List<int> favNumbers = new List<int>();

            // List of Dog objects
            List<Dog> myDogs = new List<Dog>();
            myDogs.Add(new Dog("Kirby", 15));
            myDogs.Add(new Dog("Ruby", 3));

            // List of structs
            List<Point3D> points = new List<Point3D>();
            points.Add(new Point3D(1.0, 1.0, 0.5, "Here"));
            points.Add(new Point3D(2.0, 2.0, 0.5, "There"));



About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: