Using system;
Using system. collections;
Using system. Collections. Specialized;
Namespace set and Synchronization
{
/// <Summary>
/// Summary of class1.
/// </Summary>
Class class1
{
Public static void demolockcollection ()
{
Stringdictionary sdic = new stringdictionary ();
If (! Sdic. issynchronized)
{
Sdic. Add ("Xiaohua", "Garden Road ");
Sdic ["Xiao Yang"] = "xinxingqiao ";
Foreach (string key in sdic. Keys)
Console. writeline ("name = {0}, address = {1}", key, sdic [Key]);
}
Else
{
// Do not adopt synchronous processing Code
}
}
[Stathread]
Static void main (string [] ARGs)
{
// The following code is used to run the class demolockcollection ().
Class1.demolockcollection ();
// The following code is another hashtable routine.
// Create and initialize a hash table
Hashtable myht = new hashtable ();
Myht. Add (0, "zero ");
Myht. Add (1, "one ");
Myht. Add (2, "two ");
Myht. Add (3, "three ");
Myht. Add (4, "four ");
// Create thread-Safe Packaging
Hashtable mysyncdht = hashtable. synchronized (myht );
// Display the synchronization status of the Kazakh Greek table
Console. writeline ("myht {0}.", myht. issynchronized? "Synchronized": "No synchronization ");
Console. writeline ("mysncdht {0}.", mysyncdht. issynchronized? "Synchronized": "No synchronization ");
// Traverse the hash
Foreach (Object key in mysyncdht. Keys)
Console. writeline ("Key = {0}, value = {1]", key, mysyncdht [Key]);
Console. Read ();
}
}
}