ICollection is an interface that contains size, enumerations, and synchronization methods for all nongeneric collections. It is the base interface for classes in System.Collections namespace. IsSynchronized is also a property of the ICollection interface. This property in C# is defined under System.Collections namespace and a part of System.Runtime.dll assembly. It is used to check whether the access to the ICollection is thread-safe i.e, synchronized or not. It will return true if the access to the IsCollection is thread-safe. Otherwise, it will return false.
Syntax:
public bool IsSynchronized { get; }
Return type: The return type of this property is Boolean, i.e. either true or false. It will return true if the access to the IsCollection is thread-safe (or synchronized). Or it will return false when the access to the IsCollection is not thread-safe (or non-synchronized)
Example: In this example, we have initialized str with string literals. Then, we are passing it to the Display() function as a parameter. Display() method accepts it as an ICollection interface. Finally, we have used ICollection.IsSynchronized property on it.
// C# program to demonstrate the working of // ICollection.IsSynchronized property using System;
using System.Collections;
class GFG {
// Display function public static void Display(ICollection iCollection)
{ // Apply iCollection.IsSynchronized property
// on the ICollection interface
Console.WriteLine( "IsSynchronized: {0}" ,
iCollection.IsSynchronized);
} // Driver code static public void Main()
{ // Initializing a string array
string [] str = { "Bhuwanesh" , "Nainwal" ,
"Harshit" , "Nainwal" };
// Calling display function
Display(str);
Console.ReadLine();
} } |
IsSynchronized: False