What does Array.IsSynchronized property of array class do in C#?


The Array.IsSynchronized property in C gets a value indicating whether access to the Array is synchronized.

The IsSynchronized property is implemented by Arrays because it is needed by the System.Collections.ICollection interface. Classes using arrays can also implement own synchronization using the SyncRoot property.

The following is the syntax −

public bool IsSynchronized { get; }

The Array.IsSynchronized property implementation is the same like the SyncRoot property −

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;

class Program {
   static void Main() {
      Array arr = new int[] { 2, 1, 9, 4, 8, 6,8 };
      lock(arr.SyncRoot) {
         foreach (Object val in arr)
         Console.WriteLine(val);
      }
   }
}

Output

2
1
9
4
8
6
8

Updated on: 20-Jun-2020

61 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements