C# Array IsSynchronized

Description

Array IsSynchronized gets a value indicating whether access to the Array is synchronized (thread safe).

Syntax

Array.IsSynchronized has the following syntax.


public bool IsSynchronized { get; }

Example

The following code example shows how to lock an array during the entire enumeration by using the SyncRoot property.


using System;/*from   ww w.j a  v a2s .  c  o m*/
public class MainClass{
  public static void Main(String[] argv){
    Array myArray = new int[] { 1, 2, 4 };
    lock(myArray.SyncRoot) 
    {
        foreach (Object item in myArray)
            Console.WriteLine(item);
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version