Hashtable.IsSynchronized Property is used to get a value indicating whether access to the Hashtable is synchronized(thread-safe).
Syntax:
public virtual bool IsSynchronized { get; }
Return Value: This property return true if access to the Hashtable is synchronized (thread-safe), otherwise it returns false. The default is false.
Below programs illustrate the use of above-discussed property:
Example 1:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Hashtable has1 = new Hashtable();
has1.Add( "1" , "Welcome" );
has1.Add( "2" , "to" );
has1.Add( "3" , "geeks" );
has1.Add( "4" , "for" );
has1.Add( "5" , "geeks" );
Hashtable smyTable = Hashtable.Synchronized(has1);
Console.WriteLine( "has1 is {0}." , has1.IsSynchronized ?
"Synchronized" : "Not Synchronized" );
Console.WriteLine( "smyTable is {0}." , smyTable.IsSynchronized ?
"Synchronized" : "Not Synchronized" );
}
}
|
Output:
has1 is Not Synchronized.
smyTable is Synchronized.
Example 2:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Hashtable myTable = new Hashtable();
myTable.Add( "G" , "Geeks" );
myTable.Add( "C" , "C#" );
myTable.Add( "D" , "Data Structures" );
myTable.Add( "Q" , "Quiz" );
Console.WriteLine(myTable.IsSynchronized);
}
}
|
Note: A Hashtable can support one writer and multiple readers concurrently. To support multiple writers, all operations must be done through the wrapper returned by the Synchronized method.
Reference:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!