Visual C++ .NET/Collections/StringCollection — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:05, 26 мая 2010
Содержание
- 1 Add a range to StringCollection
- 2 Add keys from a StringDictionary to an ArrayList
- 3 Add key value pair to StringDictionary
- 4 Add string to StringCollection
- 5 Assign string value to StringCollection by indexer
- 6 Assign value to a StringDictionary by using indexer
- 7 Get all keys from a StringDictionary
- 8 Get Enumerator from StringCollection
- 9 Get value from StringDictionary by key
- 10 Insert string to a StringCollection at specific position
- 11 Loop through a StringDictionary with for loop
- 12 Using for each loop with StringCollection
Add a range to StringCollection
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
array<String^>^ tmpstr = gcnew array<String^> {"Third", "Fourth" };
strcol->AddRange(tmpstr);
}
Add keys from a StringDictionary to an ArrayList
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
strdict["C"] = "c";
ArrayList ^alist = gcnew ArrayList();
alist->AddRange(strdict->Keys);
alist->Sort();
}
Add key value pair to StringDictionary
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
}
Add string to StringCollection
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
strcol->Add("The first String");
}
Assign string value to StringCollection by indexer
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
array<String^>^ tmpstr = gcnew array<String^> {"Third", "Fourth" };
strcol->AddRange(tmpstr);
strcol[0] = "First";
strcol->Insert(1, "Second");
}
Assign value to a StringDictionary by using indexer
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
strdict["C"] = "c";
}
Get all keys from a StringDictionary
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
strdict["C"] = "c";
ArrayList ^alist = gcnew ArrayList();
alist->AddRange(strdict->Keys);
alist->Sort();
}
Get Enumerator from StringCollection
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
array<String^>^ tmpstr = gcnew array<String^> {"Third", "Fourth" };
strcol->AddRange(tmpstr);
StringEnumerator ^strenum = strcol->GetEnumerator();
while ( strenum->MoveNext())
{
Console::WriteLine(strenum->Current);
}
}
Get value from StringDictionary by key
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
strdict["C"] = "c";
ArrayList ^alist = gcnew ArrayList();
alist->AddRange(strdict->Keys);
alist->Sort();
for (int i = 0; i < alist->Count; i++)
{
Console::WriteLine("{0,10}:\t{1}", alist[i],
strdict[(String^)alist[i]]);
}
}
Insert string to a StringCollection at specific position
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
array<String^>^ tmpstr = gcnew array<String^> {"Third", "Fourth" };
strcol->AddRange(tmpstr);
strcol->Insert(1, "Second");
}
Loop through a StringDictionary with for loop
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringDictionary ^strdict = gcnew StringDictionary();
strdict->Add("D", "d");
strdict->Add("F", "f");
strdict["C"] = "c";
ArrayList ^alist = gcnew ArrayList();
alist->AddRange(strdict->Keys);
alist->Sort();
for (int i = 0; i < alist->Count; i++)
{
Console::WriteLine("{0,10}:\t{1}", alist[i],
strdict[(String^)alist[i]]);
}
}
Using for each loop with StringCollection
#include "stdafx.h"
#using <system.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
StringCollection ^strcol = gcnew StringCollection();
array<String^>^ tmpstr = gcnew array<String^> {"Third", "Fourth" };
strcol->AddRange(tmpstr);
for each (String^ s in strcol)
Console::WriteLine(s);
}