Programming Articles

Page 711 of 2547

Check if two OrderedDictionary objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 166 Views

The OrderedDictionary class in C# represents a collection of key-value pairs that are accessible by both key and index. When comparing two OrderedDictionary objects for equality, you need to understand that the default Equals() method performs reference equality, not content equality. The Equals() method only returns true if both variables reference the same object in memory. For content-based comparison, you need a custom implementation. Syntax Following is the syntax for using the Equals() method − bool isEqual = dict1.Equals(dict2); Using Reference Equality (Default Behavior) Different Objects with Same Content using ...

Read More

How to sort 0,1,2 in an Array (Dutch National Flag) without extra space using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 320 Views

The Dutch National Flag problem is a classic algorithm challenge that sorts an array containing only 0s, 1s, and 2s in a single pass without using extra space. This problem was originally described by Dutch computer scientist Edsger Dijkstra and is also known as the Three-Way Partitioning algorithm. The algorithm uses three pointers to partition the array into three regions: all 0s on the left, all 1s in the middle, and all 2s on the right. Algorithm Overview The algorithm maintains three pointers − low − Points to the boundary of the 0s region mid ...

Read More

Check if two SortedList objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 185 Views

To check if two SortedList objects are equal in C#, you can use the Equals() method. However, it's important to understand that this method checks for reference equality, not content equality. Two SortedList objects are considered equal only if they reference the same object in memory. Syntax Following is the syntax for checking equality between two SortedList objects − bool isEqual = sortedList1.Equals(sortedList2); Using Equals() for Reference Equality The Equals() method returns true only when both variables reference the same SortedList object − using System; using System.Collections; public class Demo ...

Read More

Check if Input, Output and Error is redirected on the Console or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 280 Views

The Console class in C# provides properties to check if standard input, output, or error streams are redirected from their default console locations. This is useful when your application needs to behave differently based on how it's being executed. Console Redirection Properties The Console class offers three boolean properties to check redirection status − Console.IsInputRedirected // Checks if input is redirected Console.IsOutputRedirected // Checks if output is redirected Console.IsErrorRedirected // Checks if error is redirected Checking Input Redirection To check if the input stream is redirected ...

Read More

StringDictionary Class in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 275 Views

The StringDictionary class implements a hash table with the key and the value strongly typed to be strings rather than objects. It is part of the System.Collections.Specialized namespace and provides a case-insensitive string-based collection. Note: The StringDictionary class is considered obsolete. For new development, use Dictionary which provides better performance and more features. Syntax Following is the basic syntax to create and use a StringDictionary − StringDictionary stringDict = new StringDictionary(); stringDict.Add("key", "value"); string value = stringDict["key"]; Properties Following are the key properties of the StringDictionary class − ...

Read More

Remove the entry at specified index from OrderedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 141 Views

The OrderedDictionary class in C# provides the RemoveAt() method to remove an entry at a specified index. This method removes the key-value pair located at the given zero-based index position while maintaining the order of remaining elements. Syntax Following is the syntax for the RemoveAt() method − public void RemoveAt(int index) Parameters index − The zero-based index of the entry to remove from the OrderedDictionary. Using RemoveAt() Method The following example demonstrates removing an entry at a specific index from an OrderedDictionary − using System; using System.Collections; ...

Read More

How to rotate an array k time using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

Array rotation is a common programming problem where elements are shifted by k positions. When we rotate an array to the right by k positions, the last k elements move to the beginning, and the remaining elements shift right. For example, if we have array [1, 2, 3, 4, 5] and rotate it right by 2 positions, we get [4, 5, 1, 2, 3]. Algorithm The most efficient approach uses the reversal algorithm which works in three steps − Reverse the entire array Reverse the first k elements Reverse the remaining elements from position k ...

Read More

Remove the entry with specified key from ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

The ListDictionary class in C# provides the Remove() method to delete entries by their key. This method removes the key-value pair associated with the specified key from the dictionary and returns no value. Syntax Following is the syntax for removing an entry from a ListDictionary − listDictionary.Remove(key); Parameters key − The key of the entry to remove from the ListDictionary. Return Value The Remove() does not return a value. It simply removes the specified key-value pair if the key exists. Using Remove() Method Here's how to remove ...

Read More

Check if HybridDictionary is Synchronized in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 166 Views

The HybridDictionary class in C# provides the IsSynchronized property to check if the dictionary is thread-safe for multi-threaded operations. By default, HybridDictionary is not synchronized, meaning it is not thread-safe. A HybridDictionary automatically switches between a ListDictionary (for small collections) and a Hashtable (for larger collections) based on the number of elements, but remains unsynchronized unless explicitly wrapped. Syntax The IsSynchronized property returns a boolean value indicating thread safety − bool isSync = hybridDictionary.IsSynchronized; To create a synchronized wrapper around a HybridDictionary − HybridDictionary syncDict = (HybridDictionary)HybridDictionary.Synchronized(originalDict); Using IsSynchronized ...

Read More

Char.IsSeparator () Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 225 Views

The Char.IsSeparator() method in C# indicates whether the specified Unicode character is categorized as a separator character. This method checks if the character belongs to the separator category in Unicode, which includes space characters, line separators, and paragraph separators. Syntax Following is the syntax − public static bool IsSeparator(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is categorized as a separator; otherwise, false. Types of Separator Characters The Unicode separator category includes three subcategories − Space Separator ...

Read More
Showing 7101–7110 of 25,466 articles
« Prev 1 709 710 711 712 713 2547 Next »
Advertisements