Array.IsSynchronized गुण इंगित करता है कि सरणी तक पहुंच सिंक्रनाइज़्ड (थ्रेड-सेफ) है या नहीं। सभी मानक सरणियाँ IsSynchronized = false लौटाती हैं; सिंक्रनाइज़्ड रैपर के लिए Array.Synchronized का उपयोग करें (लेकिन ध्यान दें कि सरणियों के लिए कोई सिंक्रनाइज़्ड रैपर नहीं है; यह गुण हमेशा false लौटाता है)।
उदाहरण 1: खाली सरणी
using System;
public class Demo
{
public static void Main()
{
string[] products = new string[] { };
Console.WriteLine("One or more planets begin with 'E'? = {0}",
Array.Exists(products, ele => ele.StartsWith("E")));
Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);
Console.WriteLine("Is the array read only? = " + products.IsReadOnly);
Console.WriteLine("Is the array synchronized? = " + products.IsSynchronized);
}
}
आउटपुट
One or more planets begin with 'E'? = False Is the array having fixed size? = True Is the array read only? = False Is the array synchronized? = False
उदाहरण 2: दो स्ट्रिंग सरणियाँ
using System;
public class Demo
{
public static void Main()
{
String[] strArr1 = new String[3] { "John", "Jacob", "Tim" };
String[] strArr2 = new String[3] { "Tom", "Brad", "Bradley" };
Console.WriteLine("First String array...");
foreach (string val in strArr1)
{
Console.WriteLine(val);
}
Console.WriteLine("Is the 1st array having fixed size? = " + strArr1.IsFixedSize);
Console.WriteLine("Is the 1st array read only? = " + strArr1.IsReadOnly);
Console.WriteLine("Is the 1st array synchronized? = " + strArr1.IsSynchronized);
Console.WriteLine("\nSecond String array...");
foreach (string val in strArr2)
{
Console.WriteLine(val);
}
Console.WriteLine("Is the 2nd array having fixed size? = " + strArr2.IsFixedSize);
Console.WriteLine("Is the 2nd array read only? = " + strArr2.IsReadOnly);
Console.WriteLine("Is the 2nd array synchronized? = " + strArr2.IsSynchronized);
Console.WriteLine("Are both the array objects equal? = " + strArr1.Equals(strArr2));
}
}
आउटपुट
First String array... John Jacob Tim Is the 1st array having fixed size? = True Is the 1st array read only? = False Is the 1st array synchronized? = False Second String array... Tom Brad Bradley Is the 2nd array having fixed size? = True Is the 2nd array read only? = False Is the 2nd array synchronized? = False Are both the array objects equal? = False
सभी C# सरणियों में IsFixedSize = true, IsReadOnly = false, IsSynchronized = false होता है। ये गुण IList इंटरफ़ेस से आते हैं जिसे सरणियाँ लागू करती हैं। थ्रेड सुरक्षा के लिए, मैन्युअल लॉकिंग या थ्रेड-सेफ संग्रह जैसे ConcurrentBag का उपयोग करें।