C# | Check if an array is synchronized (thread safe) or not (original) (raw)

Last Updated : 01 Feb, 2019

Array.IsSynchronized Property is used to get a value which indicates whether access to the Array is synchronized (thread-safe) or not.Syntax:

public bool IsSynchronized { get; }

Property Value: This property always returns false for all arrays. Below programs illustrate the use of above-discussed property:Example 1:

CSharp `

// C# program to illustrate // IsSynchronized Property of // Array class using System; namespace geeksforgeeks {

class GFG {

// Main Method
public static void Main()
{

    // The array with dimensions  
    // specified 4 row and 2 column. 
    int[, ] arr = new int[4, 2] {{1, 2 }, {3, 4},  
                                        {5, 6 }, {7, 8}};

    // Here we check whether the
    // array is synchronized (thread safe)
    // or not
    Console.WriteLine("Result: " + arr.IsSynchronized);
}

} }

`

Example 2:

CSharp `

// C# program to illustrate // IsSynchronized Property of // Array class using System; namespace geeksforgeeks {

class GFG {

// Main Method
public static void Main()
{

    // declares an 1D Array of string.
    string[] topic;

    // allocating null to array
    topic = new string[] { null };

    // Here we check whether the
    // array is synchronized (thread safe)
    // or not
    Console.WriteLine("Result: " + topic.IsSynchronized);
}

} }

`

Note:

Reference:

Similar Reads