Remove from the specified index of a SortedList in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

232 Views

The SortedList class in C# provides the RemoveAt() method to remove a key-value pair from a specified index. The RemoveAt() method removes the element at the specified zero-based index and automatically shifts the remaining elements to fill the gap. Syntax Following is the syntax for the RemoveAt() method − public virtual void RemoveAt(int index) Parameters index − The zero-based index of the element to remove. Key Points The index is zero-based, meaning the first element is at index 0. After removal, all elements at higher indices are shifted ... Read More

How to create a StringCollection in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

173 Views

The StringCollection class in C# is a specialized collection that stores only string values. It is part of the System.Collections.Specialized namespace and provides methods to add, remove, and manipulate strings efficiently. StringCollection is useful when you need to work exclusively with string data and want type safety without the overhead of generic collections. Syntax Following is the syntax for creating a StringCollection − StringCollection collection = new StringCollection(); To add multiple strings at once using an array − string[] array = {"string1", "string2", "string3"}; collection.AddRange(array); Creating and Populating a ... Read More

Difference between SortedList and SortedDictionary in C#

Nitin Sharma
Updated on 17-Mar-2026 07:04:36

976 Views

Both SortedList and SortedDictionary in C# are generic collections that store key-value pairs in sorted order based on the key. However, they differ significantly in their internal implementation, memory usage, and performance characteristics. Understanding these differences helps you choose the right collection for your specific use case based on performance requirements and usage patterns. Syntax Following is the syntax for declaring a SortedList − SortedList sortedList = new SortedList(); Following is the syntax for declaring a SortedDictionary − SortedDictionary sortedDictionary = new SortedDictionary(); Key Differences ... Read More

How to replace line breaks in a string in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

2K+ Views

In C#, you often need to remove or replace line breaks from strings when processing text data. Line breaks can appear as (line feed), \r (carriage return), or \r (Windows-style line endings). This article demonstrates different approaches to handle line breaks in strings. Common Line Break Characters Different operating systems use different line break characters − − Line Feed (LF), used on Unix/Linux/Mac \r − Carriage Return (CR), used on older Mac systems \r − Carriage Return + Line Feed (CRLF), used on Windows Line Break Types ... Read More

Get the TypeCode for value type Char in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

265 Views

The TypeCode for a char value type in C# can be obtained using the GetTypeCode() method. This method returns TypeCode.Char, which is an enumeration value that identifies the char data type. The GetTypeCode() method is inherited from the IConvertible interface and provides a way to determine the underlying type of a value at runtime. Syntax Following is the syntax to get the TypeCode for a char value − TypeCode typeCode = charVariable.GetTypeCode(); Return Value The method returns TypeCode.Char for char data types, which is part of the TypeCode enumeration. Using GetTypeCode() ... Read More

How to get all elements of a List that match the conditions specified by the predicate in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

700 Views

To get all elements of a List that match specific conditions, C# provides the FindAll method which accepts a predicate − a delegate that defines the filtering criteria. This method returns a new List containing only the elements that satisfy the condition. Syntax Following is the syntax for using FindAll with a predicate − List result = list.FindAll(predicate); The predicate can be defined as a method, lambda expression, or anonymous delegate − // Method predicate private static bool MethodName(T item) { return condition; } // Lambda expression predicate ... Read More

Executing C# code in Linux

Ajay yadav
Updated on 17-Mar-2026 07:04:36

6K+ Views

The .NET ecosystem was traditionally limited to Windows, but Microsoft's introduction of Mono changed this landscape. Mono enables the execution of .NET applications on Linux systems, making them run as if they were native Linux packages rather than Windows executable files. What is Mono? Mono is an open-source, cross-platform implementation of Microsoft's .NET Framework. It allows developers to run .NET applications on various platforms including Linux and macOS. Mono provides a complete development stack that supports Windows Forms, LINQ, XML web services, ADO.NET, and ASP.NET using the same CLR namespaces. Cross-Platform .NET with ... Read More

How to find items in one list that are not in another list in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

15K+ Views

Finding items in one list that are not present in another list is a common task in C# programming. LINQ provides multiple approaches to solve this problem, with the Except() method being the most straightforward for simple data types and the Where() clause being more flexible for complex objects. Syntax Using the Except() method for simple types − var result = list1.Except(list2); Using Where() clause with All() for complex objects − var result = list1.Where(item1 => list2.All(item2 => condition)); Using Except() Method The Except() method is a LINQ set ... Read More

Check whether the specified Unicode character is a letter or a decimal digit in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

236 Views

To check whether the specified Unicode character is a letter or a decimal digit in C#, use the Char.IsLetterOrDigit() method. This method returns true if the character is a letter (uppercase or lowercase) or a decimal digit (0-9), and false otherwise. Syntax Following is the syntax for the Char.IsLetterOrDigit() method − public static bool IsLetterOrDigit(char c) Parameters c: The Unicode character to evaluate. Return Value Returns true if the character is a letter or decimal digit; otherwise, false. Using IsLetterOrDigit with Decimal Digits Example ... Read More

How to get the HashCode of the tuple in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

244 Views

To get the HashCode of a tuple in C#, you can use the GetHashCode() method. This method returns an integer hash code that represents the tuple's value. Tuples with identical values will have the same hash code, while tuples with different values will typically have different hash codes. Syntax Following is the syntax for getting the hash code of a tuple − int hashCode = tuple.GetHashCode(); Return Value The GetHashCode() method returns a 32-bit signed integer that serves as a hash code for the tuple. Equal tuples will always return the same hash ... Read More

Advertisements