Visual C++ .NET/Collections/StringCollection — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15: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
<source lang="csharp">
- 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);
}
</source>
Add keys from a StringDictionary to an ArrayList
<source lang="csharp">
- 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();
}
</source>
Add key value pair to StringDictionary
<source lang="csharp">
- 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");
}
</source>
Add string to StringCollection
<source lang="csharp">
- 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");
}
</source>
Assign string value to StringCollection by indexer
<source lang="csharp">
- 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");
}
</source>
Assign value to a StringDictionary by using indexer
<source lang="csharp">
- 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";
}
</source>
Get all keys from a StringDictionary
<source lang="csharp">
- 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();
}
</source>
Get Enumerator from StringCollection
<source lang="csharp">
- 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); }
}
</source>
Get value from StringDictionary by key
<source lang="csharp">
- 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]]); }
}
</source>
Insert string to a StringCollection at specific position
<source lang="csharp">
- 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");
}
</source>
Loop through a StringDictionary with for loop
<source lang="csharp">
- 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]]); }
}
</source>
Using for each loop with StringCollection
<source lang="csharp">
- 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);
}
</source>