StringCollection Class

Represents a collection of strings.

System.Object
  System.Collections.Specialized.StringCollection
    System.Configuration.CommaDelimitedStringCollection

Namespace:  System.Collections.Specialized
Assembly:  System (in System.dll)

[<SerializableAttribute>]
type StringCollection =  
    class 
        interface IList 
        interface ICollection 
        interface IEnumerable 
    end

The StringCollection type exposes the following members.

  NameDescription
Public methodStringCollectionInitializes a new instance of the StringCollection class.
Top

  NameDescription
Public propertyCountGets the number of strings contained in the StringCollection.
Public propertyIsReadOnlyGets a value indicating whether the StringCollection is read-only.
Public propertyIsSynchronizedGets a value indicating whether access to the StringCollection is synchronized (thread safe).
Public propertyItemGets or sets the element at the specified index.
Public propertySyncRootGets an object that can be used to synchronize access to the StringCollection.
Top

  NameDescription
Public methodAddAdds a string to the end of the StringCollection.
Public methodAddRangeCopies the elements of a string array to the end of the StringCollection.
Public methodClearRemoves all the strings from the StringCollection.
Public methodContainsDetermines whether the specified string is in the StringCollection.
Public methodCopyToCopies the entire StringCollection values to a one-dimensional array of strings, starting at the specified index of the target array.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns a StringEnumerator that iterates through the StringCollection.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfSearches for the specified string and returns the zero-based index of the first occurrence within the StringCollection.
Public methodInsertInserts a string into the StringCollection at the specified index.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves the first occurrence of a specific string from the StringCollection.
Public methodRemoveAtRemoves the string at the specified index of the StringCollection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast(TResult)Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType(TResult)Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToCopies the entire StringCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns a IEnumerator that iterates through the StringCollection.
Explicit interface implemetationPrivate methodIList.AddAdds an object to the end of the StringCollection.
Explicit interface implemetationPrivate methodIList.ContainsDetermines whether an element is in the StringCollection.
Explicit interface implemetationPrivate methodIList.IndexOfSearches for the specified Object and returns the zero-based index of the first occurrence within the entire StringCollection.
Explicit interface implemetationPrivate methodIList.InsertInserts an element into the StringCollection at the specified index.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeGets a value indicating whether the StringCollection object has a fixed size.
Explicit interface implemetationPrivate propertyIList.IsReadOnlyGets a value indicating whether the StringCollection object is read-only.
Explicit interface implemetationPrivate propertyIList.ItemGets or sets the element at the specified index.
Explicit interface implemetationPrivate methodIList.RemoveRemoves the first occurrence of a specific object from the StringCollection.
Top

StringCollection accepts a null reference (Nothing in Visual Basic) as a valid value and allows duplicate elements.

String comparisons are case-sensitive.

Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.

The following code example demonstrates several of the properties and methods of StringCollection.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

This implementation does not provide a synchronized (thread safe) wrapper for a StringCollection, but derived classes can create their own synchronized versions of the StringCollection using the SyncRoot property.

Enumerating through a collection is intrinsically not a thread safe procedure. Even when a collection is synchronized, other threads can 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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft