
- 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 a SortedList object is synchronized in C#
To check if a SortedList object is synchronized, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList(); list.Add("1", "One"); list.Add("2", "Two"); list.Add("3", "Three"); list.Add("4", "Four"); list.Add("5", "Five"); list.Add("6", "Six"); list.Add("7", "Seven"); list.Add("8", "Eight"); Console.WriteLine("Key and Value of SortedList...."); foreach(DictionaryEntry k in list ) Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value ); Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Five")); SortedList sortedList = SortedList.Synchronized(list); Console.WriteLine("Is the SortedList synchronized? = "+sortedList.IsSynchronized); } }
Output
This will produce the following output −
Key and Value of SortedList.... Key: 1, Value: One Key: 2, Value: Two Key: 3, Value: Three Key: 4, Value: Four Key: 5, Value: Five Key: 6, Value: Six Key: 7, Value: Seven Key: 8, Value: Eight Is the SortedList having the value? True Is the SortedList synchronized? = True
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList(); list.Add("1", "One"); list.Add("2", "Two"); list.Add("3", "Three"); list.Add("4", "Four"); list.Add("5", "Five"); list.Add("6", "Six"); list.Add("7", "Seven"); list.Add("8", "Eight"); Console.WriteLine("Key and Value of SortedList...."); foreach(DictionaryEntry k in list ) Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value ); Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Ten")); Console.WriteLine("Is the SortedList synchronized? = "+list.IsSynchronized); } }
Output
This will produce the following output −
Key and Value of SortedList.... Key: 1, Value: One Key: 2, Value: Two Key: 3, Value: Three Key: 4, Value: Four Key: 5, Value: Five Key: 6, Value: Six Key: 7, Value: Seven Key: 8, Value: Eight Is the SortedList having the value? False Is the SortedList synchronized? = False
- Related Articles
- Creating a synchronized wrapper for a SortedList object in C#
- Check if a SortedList object contains a specific value in C#
- Check if a SortedList object has a fixed size in C#
- 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 is read-only in C#
- Check if ArrayList is Synchronized (thread safe) in C#
- Check if an array is synchronized or not in C#
- Check whether a SortedList object contains a specific key in C#?
- Check if two SortedList objects are equal in C#
- Search in a SortedList object in C#
- Getting the keys in a SortedList object C#
- Getting the Values in a SortedList object in C#

Advertisements