C# Hashtable Synchronized

Description

Hashtable Synchronized returns a synchronized (thread-safe) wrapper for the Hashtable.

Syntax

Hashtable.Synchronized has the following syntax.


[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
public static Hashtable Synchronized(
  Hashtable table
)

Parameters

Hashtable.Synchronized has the following parameters.

  • table - The Hashtable to synchronize.

Returns

Hashtable.Synchronized method returns A synchronized (thread-safe) wrapper for the Hashtable.

Example

The following example shows how to synchronize a Hashtable, determine if a Hashtable is synchronized, and use a synchronized Hashtable.


using System;/* ww w  .jav  a 2  s.c  o m*/
using System.Collections;
public class SamplesHashtable  {

   public static void Main()  {
      Hashtable myHT = new Hashtable();
      myHT.Add( 0, "zero" );
      myHT.Add( 1, "one" );
      myHT.Add( 2, "two" );

      Hashtable mySyncdHT = Hashtable.Synchronized( myHT );

      Console.WriteLine(myHT.IsSynchronized);
      Console.WriteLine(mySyncdHT.IsSynchronized);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack