System.Collections.Specialized.CollectionsUtil Class

Assembly: System.dll
Namespace: System.Collections.Specialized
Summary
Creates collections that ignore the case in strings.
C# Syntax:
public class CollectionsUtil
Thread Safety
A Hashtable can safely support one writer and multiple readers concurrently. To support multiple writers, all operations must be done through the wrapper returned by the Hashtable.Synchronized method.

A SortedList can safely support multiple readers concurrently, as long as the collection is not modified. To guarantee the thread safety of the SortedList, all operations must be done through the wrapper returned by the SortedList.Synchronized method.

Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Remarks
These methods generate a case-insensitive instance of the collection using case-insensitive implementations of the hash code provider and the comparer. The resulting instance can be used like any other instances of that class, although it may behave differently.

For example, suppose two objects with the keys "hello" and "HELLO" are to be added to a hash table. A case-sensitive hash table would create two different entries; whereas, a case-insensitive hash table would throw an exception when adding the second object.

See also:
System.Collections.Specialized Namespace | System.Collections

System.Collections.Specialized.CollectionsUtil Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Methods
CreateCaseInsensitiveHashtable Overloaded:
CreateCaseInsensitiveHashtable()

Creates a new case-insensitive instance of the Hashtable class with the default initial capacity.
CreateCaseInsensitiveHashtable Overloaded:
CreateCaseInsensitiveHashtable(IDictionary d)

Copies the entries from the specified dictionary to a new case-insensitive instance of the Hashtable class with the same initial capacity as the number of entries copied.
CreateCaseInsensitiveHashtable Overloaded:
CreateCaseInsensitiveHashtable(int capacity)

Creates a new case-insensitive instance of the Hashtable class with the specified initial capacity.
CreateCaseInsensitiveSortedList Creates a new instance of the SortedList class that ignores the case of strings.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Collections.Specialized.CollectionsUtil Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public CollectionsUtil();

Return to top


Overloaded Method: CreateCaseInsensitiveHashtable()
Summary
Creates a new case-insensitive instance of the Hashtable class with the default initial capacity.
C# Syntax:
public static Hashtable CreateCaseInsensitiveHashtable();
Return Value:
A new case-insensitive instance of the Hashtable class with the default initial capacity.
Remarks
The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.
See also:
Hashtable | CaseInsensitiveHashCodeProvider | CaseInsensitiveComparer

Return to top


Overloaded Method: CreateCaseInsensitiveHashtable(
   IDictionary d
)
Summary
Copies the entries from the specified dictionary to a new case-insensitive instance of the Hashtable class with the same initial capacity as the number of entries copied.
C# Syntax:
public static Hashtable CreateCaseInsensitiveHashtable(
   IDictionary d
);
Parameters:

d

The IDictionary to copy to a new case-insensitive Hashtable.

Return Value:
A new case-insensitive instance of the Hashtable class containing the entries from the specified IDictionary.
Exceptions
Exception Type Condition
ArgumentNullException d is null.
Remarks
The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.
See also:
Hashtable | IDictionary | CaseInsensitiveHashCodeProvider | CaseInsensitiveComparer

Return to top


Overloaded Method: CreateCaseInsensitiveHashtable(
   int capacity
)
Summary
Creates a new case-insensitive instance of the Hashtable class with the specified initial capacity.
C# Syntax:
public static Hashtable CreateCaseInsensitiveHashtable(
   int capacity
);
Parameters:

capacity

The approximate number of entries that the Hashtable can initially contain.

Return Value:
A new case-insensitive instance of the Hashtable class with the specified initial capacity.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException capacity is less than zero.
Remarks
The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.
See also:
Hashtable | CaseInsensitiveHashCodeProvider | CaseInsensitiveComparer

Return to top


Method: CreateCaseInsensitiveSortedList()
Summary
Creates a new instance of the SortedList class that ignores the case of strings.
C# Syntax:
public static SortedList CreateCaseInsensitiveSortedList();
Return Value:
A new instance of the SortedList class that ignores the case of strings.
Remarks
The new SortedList instance is sorted according to the CaseInsensitiveComparer.
See also:
SortedList | CaseInsensitiveComparer

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~CollectionsUtil();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.