#835 – A Generic List Can Store Value-Typed or Reference-Typed Objects
May 2, 2013 Leave a comment
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>(); favNumbers.Add(5); favNumbers.Add(49); // 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"));