Collection-> synchronous execution of Collections

Source: Internet
Author: User

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.