The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
StringCollection::Add Method (String^)
.NET Framework (current version)
Adds a string to the end of the StringCollection.
Assembly: System (in System.dll)
Parameters
- value
-
Type:
System::String^
The string to add to the end of the StringCollection. The value can be null.
StringCollection accepts null as a valid value and allows duplicate elements.
If Count is less than the capacity, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.
The following code example adds new elements to the StringCollection.
#using <System.dll> using namespace System; using namespace System::Collections; using namespace System::Collections::Specialized; void PrintValues( IEnumerable^ myCol ); int main() { // Creates and initializes a new StringCollection. StringCollection^ myCol = gcnew StringCollection; Console::WriteLine( "Initial contents of the StringCollection:" ); PrintValues( myCol ); // Adds a range of elements from an array to the end of the StringCollection. array<String^>^myArr = {"RED","orange","yellow","RED","green","blue","RED","indigo","violet","RED"}; myCol->AddRange( myArr ); Console::WriteLine( "After adding a range of elements:" ); PrintValues( myCol ); // Adds one element to the end of the StringCollection and inserts another at index 3. myCol->Add( "* white" ); myCol->Insert( 3, "* gray" ); Console::WriteLine( "After adding \"* white\" to the end and inserting \"* gray\" at index 3:" ); PrintValues( myCol ); } void PrintValues( IEnumerable^ myCol ) { IEnumerator^ myEnum = myCol->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ obj = safe_cast<Object^>(myEnum->Current); Console::WriteLine( " {0}", obj ); } Console::WriteLine(); } /* This code produces the following output. Initial contents of the StringCollection: After adding a range of elements: RED orange yellow RED green blue RED indigo violet RED After adding "* white" to the end and inserting "* gray" at index 3: RED orange yellow * gray RED green blue RED indigo violet RED * white */
Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 10
.NET Framework
Available since 1.1
Show: