
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Check if ArrayList is Synchronized (thread safe) in C#
To check if ArrayList is synchronized, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list1 = new ArrayList(); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); list1.Add("E"); list1.Add("F"); list1.Add("G"); list1.Add("H"); list1.Add("I"); Console.WriteLine("Elements in ArrayList1..."); foreach (string res in list1) { Console.WriteLine(res); } ArrayList list2 = new ArrayList(); list2.Add("A"); list2.Add("B"); list2.Add("C"); list2.Add("D"); list2.Add("E"); list2.Add("F"); list2.Add("G"); list2.Add("H"); list2.Add("I"); Console.WriteLine("Elements in ArrayList2..."); foreach (string res in list2) { Console.WriteLine(res); } Console.WriteLine("Is ArrayList synchronized? = "+list2.IsSynchronized); } }
Output
This will produce the following output −
Elements in ArrayList1... A B C D E F G H I Elements in ArrayList2... A B C D E F G H I Is ArrayList synchronized? = False
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list1 = new ArrayList(); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); list1.Add("Five"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list1) { Console.WriteLine(res); } ArrayList list = ArrayList.Synchronized(list1); Console.WriteLine("Is ArrayList synchronized? = "+list.IsSynchronized); } }
Output
This will produce the following output −
Elements in ArrayList... One Two Three Four Five Is ArrayList synchronized? = True
- Related Articles
- Check if ListDictionary is synchronized in C#
- Check if StringDictionary is synchronized in C#
- Check if HybridDictionary is Synchronized in C#
- Check if Hashtable is synchronized C#
- Check if a SortedList object is synchronized in C#
- Thread-Safe collections in C#
- Check if an array is synchronized or not in C#
- Thread Safe Concurrent Collection in C#
- Is Swing thread-safe in Java?
- How to understand StringBuffer is thread-safe and StringBuilder is non-thread-safe in Java?\n
- Make your collections thread-safe in C#
- Creating a synchronized wrapper for the ArrayList in C#
- Check if the ArrayList is read-only in C#
- Is Java matcher thread safe in Java?
- Get Synchronized List from ArrayList in java

Advertisements