C# ICollection.IsSynchronized Property with Examples
Last Updated :
18 Feb, 2022
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#
using System;
using System.Collections;
class GFG {
public static void Display(ICollection iCollection)
{
Console.WriteLine( "IsSynchronized: {0}" ,
iCollection.IsSynchronized);
}
static public void Main()
{
string [] str = { "Bhuwanesh" , "Nainwal" ,
"Harshit" , "Nainwal" };
Display(str);
Console.ReadLine();
}
}
|
Output
IsSynchronized: False
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...