The StringCollection class in C# provides the RemoveAt() method to remove an element from a specified index. This method removes the string at the given index and shifts all subsequent elements one position to the left. Syntax Following is the syntax for the RemoveAt() method − stringCollection.RemoveAt(int index); Parameters index − The zero-based index of the element to remove from the StringCollection. Using RemoveAt() to Remove Single Element The following example demonstrates removing an element from a specific index in a StringCollection − using System; ... Read More
The HybridDictionary class implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large. This provides optimal performance for both small and large collections by leveraging the strengths of each underlying data structure. The HybridDictionary automatically switches from ListDictionary to Hashtable when the number of elements exceeds a certain threshold (typically around 10 items), making it ideal for scenarios where the collection size is unpredictable. HybridDictionary Internal Structure Small Collection ListDictionary Linear search ... Read More
The StringDictionary class in C# provides an indexer that allows you to get or set values associated with specified keys. This indexer uses the key as a parameter and returns or assigns the corresponding value. The StringDictionary is case-insensitive and specifically designed for string keys and values. Syntax Following is the syntax for the StringDictionary indexer − public virtual string this[string key] { get; set; } To get a value − string value = stringDictionary[key]; To set a value − stringDictionary[key] = value; Parameters ... Read More
The StringCollection class in C# provides a specialized collection for storing strings. To get the number of strings in a StringCollection, use the Count property, which returns an integer representing the total number of elements in the collection. Syntax Following is the syntax for accessing the Count property − int count = stringCollection.Count; Using Count Property with Basic StringCollection Example using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol = new StringCollection(); ... Read More
The C# Console class provides built-in properties to check the status of the Caps Lock and Num Lock keys. The Console.CapsLock and Console.NumberLock properties return a boolean value indicating whether these keys are currently active. Syntax Following is the syntax to check Caps Lock status − bool capsLockStatus = Console.CapsLock; Following is the syntax to check Num Lock status − bool numLockStatus = Console.NumberLock; Return Value Console.CapsLock returns true if Caps Lock is on, false otherwise. Console.NumberLock returns true if Num Lock is on, false otherwise. ... Read More
The SortedList class in C# provides the Remove() method to remove an element with a specified key. When you remove an element, the SortedList automatically adjusts its internal structure to maintain the sorted order of the remaining elements. Syntax Following is the syntax for removing an element from a SortedList − sortedList.Remove(key); Parameters key: The key of the element to remove from the SortedList. Using Remove() with String Keys This example demonstrates removing an element with a string key from a SortedList − using System; ... Read More
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance