Programming Articles

Page 708 of 2547

Remove entry with specified key from the StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

The StringDictionary class in C# provides the Remove() method to delete entries with a specified key. This method removes both the key and its associated value from the collection. StringDictionary is case-insensitive, meaning keys are automatically converted to lowercase. Syntax Following is the syntax for the Remove() method − public virtual void Remove(string key) Parameters key − The string key to remove from the StringDictionary. Using Remove() Method Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() ...

Read More

How to get hash code for the specified key of a Hashtable in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 315 Views

To get the hash code for a specified key in a Hashtable, you need to use the GetHash() method. This method is protected in the base Hashtable class, so you must create a derived class to access it. The hash code is an integer value used internally by the hashtable to determine where to store the key-value pair. Syntax Following is the syntax to access the protected GetHash() method − public class CustomHashtable : Hashtable { public int GetHashCodeForKey(object key) { return GetHash(key); } ...

Read More

How can we update the values of a collection using LINQ in C#?

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

LINQ provides several approaches to update collection values in C#. While LINQ is primarily designed for querying data, you can combine it with other methods to modify collection elements efficiently. Using ForEach with List Collections The List class provides a ForEach method that can be used to update all elements in the collection − using System; using System.Collections.Generic; namespace DemoApplication { class Program { static void Main(string[] args) { List fruits ...

Read More

Remove from the specified index of a SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 234 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
AmitDiwan
Updated on 17-Mar-2026 178 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
Nitin Sharma
Updated on 17-Mar-2026 977 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
Nizamuddin Siddiqui
Updated on 17-Mar-2026 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
AmitDiwan
Updated on 17-Mar-2026 267 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
AmitDiwan
Updated on 17-Mar-2026 703 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

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 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
Showing 7071–7080 of 25,466 articles
« Prev 1 706 707 708 709 710 2547 Next »
Advertisements