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

CsharpProgrammingServer Side Programming

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
raja
Published on 10-Aug-2018 07:31:06
Advertisements