Collection Classes (C# Programming Guide)
The .NET Framework provides specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces, and these interfaces may be inherited to create new collection classes that fit more specialized data storage needs.
Note |
|---|
|
Applications that target version 2.0 and later of the .NET Framework should use the generic collection classes in the System.Collections.Generic namespace, which provide greater type-safety and efficiency than their non-generic counterparts. |
Collection Classes Overview
Collection Classes have the following properties
-
Collection classes are defined as part of the System.Collections or System.Collections.Generic namespace.
-
Most collection classes derive from the interfaces ICollection, IComparer, IEnumerable, IList, IDictionary, and IDictionaryEnumerator and their generic equivalents.
-
Using generic collection classes provides increased type-safety and in some cases can provide better performance, especially when storing value types. For more information, see Benefits of Generics.
Related Sections
See Also
using System;
using System.Collections.Generic;
using System.Text;
//Do not forget to use this namespace
using System.Collections;
namespace CollectionClass
{
class Program
{
static void Main()
{
//Create ArrayList Collection
ArrayList Names = new ArrayList();
//Adding objects
Names.Add("John");
Names.Add("Mike");
Names.Add("Michael");
//Write each object from Names to the Console
for (int i = 0; i < Names.Count; i++)
{
Console.WriteLine(Names[i]);
}
}
}
}
- 12/30/2011
- ann_programmer
