
- 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
Creating a synchronized wrapper for a SortedList object in C#
To create a synchronized wrapper for a SortedList object, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(){ SortedList sortedList = new SortedList(); sortedList.Add("1", "Tom"); sortedList.Add("2", "Ryan"); sortedList.Add("3", "Nathan"); Console.WriteLine("SortedList elements..."); foreach(DictionaryEntry d in sortedList){ Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value); } SortedList sortedList2 = SortedList.Synchronized(sortedList); Console.WriteLine("SortedList is synchronized? = "+sortedList2.IsSynchronized); } }
Output
This will produce the following output −
SortedList elements... Key = 1, Value = Tom Key = 2, Value = Ryan Key = 3, Value = Nathan SortedList is synchronized? = True
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main(){ SortedList sortedList = new SortedList(); sortedList.Add("1", "AB"); sortedList.Add("2", "CD"); sortedList.Add("3", "EF"); sortedList.Add("4", "GH"); sortedList.Add("5", "IJ"); sortedList.Add("6", "KL"); Console.WriteLine("SortedList elements..."); foreach(DictionaryEntry d in sortedList){ Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value); } Console.WriteLine("SortedList is synchronized? = "+sortedList.IsSynchronized); } }
Output
This will produce the following output −
SortedList elements... Key = 1, Value = AB Key = 2, Value = CD Key = 3, Value = EF Key = 4, Value = GH Key = 5, Value = IJ Key = 6, Value = KL SortedList is synchronized? = False
- Related Articles
- Creating a synchronized wrapper for the ArrayList in C#
- Creating a synchronized wrapper for the Hashtable in C#
- Check if a SortedList object is synchronized in C#
- Creating a read-only wrapper for the ArrayList in C#
- Search in a SortedList object in C#
- Getting the keys in a SortedList object C#
- Java Program to wrap a Primitive DataType in a Wrapper Object
- Getting the Values in a SortedList object in C#
- Check whether a SortedList object contains a specific key in C#?
- Check if a SortedList object contains a specific value in C#
- Check if a SortedList object has a fixed size in C#
- Getting the list of keys of a SortedList object in C#
- Getting the list of Values of a SortedList object in C#
- How to create a shallow copy of SortedList Object in C#?
- Getting index of the specified value in a SortedList object in C#

Advertisements