Csharp Articles

Page 38 of 196

Check if StringDictionary is synchronized in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 182 Views

The StringDictionary class in C# provides the IsSynchronized property to check whether the dictionary is synchronized (thread-safe). By default, StringDictionary is not synchronized, meaning it's not safe for concurrent access from multiple threads without external synchronization. Syntax Following is the syntax to check if a StringDictionary is synchronized − bool isSynchronized = stringDictionary.IsSynchronized; Properties IsSynchronized − Returns true if the StringDictionary is synchronized; otherwise, false. SyncRoot − Gets an object that can be used to synchronize access to the StringDictionary. Example 1: Basic Synchronization Check using System; using ...

Read More

Check if ArrayList is Synchronized (thread safe) in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 373 Views

The IsSynchronized property in C# is used to check if an ArrayList is synchronized (thread-safe). By default, ArrayList is not synchronized, meaning it's not safe for concurrent access by multiple threads. However, you can create a synchronized wrapper using the ArrayList.Synchronized() method. Syntax To check if an ArrayList is synchronized − bool isSync = arrayList.IsSynchronized; To create a synchronized ArrayList wrapper − ArrayList syncList = ArrayList.Synchronized(originalList); Return Value The IsSynchronized property returns a bool value: true if the ArrayList is synchronized (thread-safe) false if the ArrayList is ...

Read More

Creating a synchronized wrapper for the Hashtable in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 202 Views

A synchronized wrapper for the Hashtable in C# ensures thread-safe operations when multiple threads access the same Hashtable simultaneously. By default, Hashtable collections are not synchronized, but you can create a thread-safe version using the Hashtable.Synchronized() method. Syntax Following is the syntax for creating a synchronized Hashtable wrapper − Hashtable synchronizedHashtable = Hashtable.Synchronized(originalHashtable); To check if a Hashtable is synchronized, use the IsSynchronized property − bool isSynchronized = hashtable.IsSynchronized; Understanding Thread Safety Hashtable Thread Safety Regular Hashtable IsSynchronized ...

Read More

Creating an empty case-sensitive HybridDictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

The HybridDictionary class in C# is a collection that combines the performance benefits of both ListDictionary and Hashtable. It automatically switches between these implementations based on the number of elements. For small collections, it uses ListDictionary, and for larger collections, it switches to Hashtable for better performance. When creating a HybridDictionary, you can specify whether it should be case-sensitive or case-insensitive through its constructor parameter. Syntax Following is the syntax for creating a case-sensitive HybridDictionary − HybridDictionary dict = new HybridDictionary(false); Following is the syntax for creating a case-insensitive HybridDictionary − ...

Read More

Creating an empty HybridDictionary with specified case sensitivity in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 181 Views

The HybridDictionary class in C# is a collection that combines the benefits of both ListDictionary and Hashtable. It automatically switches from a list-based implementation to a hash table when the collection grows beyond a certain size. By default, HybridDictionary is case-sensitive, but you can specify case sensitivity behavior during initialization. Syntax Following is the syntax for creating an empty HybridDictionary with default case sensitivity − HybridDictionary dictionary = new HybridDictionary(); Following is the syntax for creating an empty HybridDictionary with specified case sensitivity − HybridDictionary dictionary = new HybridDictionary(bool caseInsensitive); ...

Read More

Getting the value at the specified index of a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 160 Views

In C#, the SortedList class provides the GetByIndex() method to retrieve the value at a specific index position. Unlike dictionary access by key, this method allows you to access values by their ordered position within the sorted collection. Syntax Following is the syntax for using GetByIndex() method − public virtual object GetByIndex(int index); Parameters index: The zero-based index of the value to retrieve from the SortedList. Return Value The method returns an object representing the value at the specified index position. If the index is out of ...

Read More

Getting the Values in a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 164 Views

The SortedList class in C# is a collection that stores key-value pairs sorted by the keys. To retrieve all values from a SortedList object, you can use the Values property, which returns an ICollection containing all the values in sorted order of their corresponding keys. Syntax Following is the syntax for accessing values in a SortedList − SortedList sortedList = new SortedList(); ICollection values = sortedList.Values; The Values property returns an ICollection that can be iterated using a foreach loop − foreach (var value in sortedList.Values) { Console.WriteLine(value); } ...

Read More

Check if SortedSet and the specified collection contain the same elements in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 150 Views

The SetEquals method in C# is used to check if a SortedSet and another collection contain exactly the same elements. This method returns true if both collections have identical elements, regardless of their order, and false otherwise. Syntax Following is the syntax for using the SetEquals method − public bool SetEquals(IEnumerable other) Parameters other − The collection to compare with the current SortedSet. Return Value Returns true if the SortedSet and the specified collection contain the same elements; otherwise, false. Using SetEquals with Different Elements ...

Read More

Get an IDictionaryEnumerator object in OrderedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 191 Views

The OrderedDictionary class in C# provides the GetEnumerator() method to obtain an IDictionaryEnumerator object. This enumerator allows you to iterate through the key-value pairs while maintaining the insertion order of elements. The IDictionaryEnumerator is specifically designed for dictionary collections and provides access to both the Key and Value properties of each element during enumeration. Syntax Following is the syntax for getting an IDictionaryEnumerator from an OrderedDictionary − IDictionaryEnumerator enumerator = orderedDictionary.GetEnumerator(); Following is the syntax for iterating through the enumerator − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Return Value The GetEnumerator()

Read More

Get object at the top of the Stack in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 370 Views

The Stack collection in C# follows the Last In, First Out (LIFO) principle. To get the object at the top of the stack without removing it, we use the Peek() method. This method returns the top element but keeps it in the stack, unlike Pop() which removes the element. Syntax Following is the syntax for the Peek() method − public T Peek() Return Value The Peek() method returns the object at the top of the stack of type T. It throws an InvalidOperationException if the stack is empty. ...

Read More
Showing 371–380 of 1,951 articles
« Prev 1 36 37 38 39 40 196 Next »
Advertisements