Removing first occurrence of object from Collection in C#

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

185 Views

The Collection.Remove() method in C# removes the first occurrence of a specified object from the collection. This method searches through the collection sequentially and removes only the first matching element it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for the Remove() method − public bool Remove(T item) Parameters item: The object to remove from the collection. The value can be null for reference types. Return Value The method returns a bool value − true: If the item was successfully found and removed false: ... Read More

C# Program to Read a String and Find the Sum of all Digits

Sabid Ansari
Updated on 17-Mar-2026 07:04:36

1K+ Views

C# is a popular object-oriented programming language used to develop Windows applications, web applications, and games. In this article, we will discuss how to write a C# program to read a string and find the sum of all digits present in the string. Approach To find the sum of digits in a string, we need to iterate through each character, check if it's a digit using char.IsDigit(), and convert it to an integer to add to our running sum. Using char.IsDigit() Method The char.IsDigit() method determines whether a character represents a decimal digit. Here's the complete ... Read More

Removing first occurrence of specified value from LinkedList in C#

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

347 Views

The LinkedList.Remove(T) method in C# removes the first occurrence of the specified value from a LinkedList. This method searches the LinkedList from the beginning and removes only the first matching node it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for removing the first occurrence of a specified value − public bool Remove(T value) Parameters value: The value to remove from the LinkedList. Return Value Returns true if the element is successfully found and removed; otherwise, false. This method also returns false if the value was ... Read More

C# Program to Check if Value exists in Hashtable

Shilpa Nadkarni
Updated on 17-Mar-2026 07:04:36

2K+ Views

The hashtable is an organized collection of key-value pairs wherein the keys are arranged as per the hash code of the key calculated using the hash function. While the keys should be non-null and unique in a hashtable, the values can be null and duplicate. The elements in the hashtable are accessed using the keys. In C#, the class Hashtable represents the hashtable collection. This class provides various properties and methods using which we can perform operations and access data in the hashtable. In this article, we will see how we can determine if a particular value is ... Read More

How to find all the permutation of the string by backtracking using C#?

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

995 Views

String permutation using backtracking is a classic algorithm that generates all possible arrangements of characters in a string. The approach works by fixing one character at a time and recursively finding permutations of the remaining characters, then backtracking to explore other possibilities. The core idea is to swap characters systematically − fix the first position with each character, find permutations of the rest, then backtrack by undoing the swap to try the next possibility. Backtracking Process for "ABC" ABC ... Read More

How to change the Foreground Color of Text in C# Console?

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

10K+ Views

To change the foreground color of text in C# console applications, use the Console.ForegroundColor property. This property accepts a ConsoleColor enumeration value and affects all subsequent text output until changed again. Syntax Following is the syntax for setting console foreground color − Console.ForegroundColor = ConsoleColor.ColorName; To reset to default colors, use − Console.ResetColor(); Available Colors The ConsoleColor enumeration provides the following color options − Color Name Description Black, DarkBlue, DarkGreen, DarkCyan Dark color variants DarkRed, DarkMagenta, DarkYellow, Gray Medium ... Read More

Get the number of key/value pairs contained in ListDictionary in C#

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

181 Views

To get the number of key/value pairs contained in ListDictionary, you use the Count property. The ListDictionary class in C# is part of the System.Collections.Specialized namespace and is optimized for small collections with typically fewer than 10 elements. The Count property returns an integer representing the total number of key/value pairs currently stored in the ListDictionary. Syntax Following is the syntax for getting the count of key/value pairs in ListDictionary − ListDictionary listDict = new ListDictionary(); int count = listDict.Count; Using Count Property Example using System; using System.Collections; using System.Collections.Specialized; ... Read More

How to check whether a List contains the elements that match the specified conditions in C#?

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

493 Views

To check whether a List contains elements that match specific conditions in C#, you can use the Exists() method. This method takes a predicate (a function that returns true or false) and returns true if at least one element in the list satisfies the condition. Syntax Following is the syntax for using List.Exists() method − public bool Exists(Predicate match) Parameters match − The predicate delegate that defines the conditions to check against the elements. Return Value Returns true if the List contains one or more elements that match the ... Read More

C# Program to Get Key based on Value in Hashtable Collection

Shilpa Nadkarni
Updated on 17-Mar-2026 07:04:36

1K+ Views

A hashtable is a collection in C# that holds items identified as key-value pairs. Unlike other data structures like the stack, queue, or ArrayList that store a single value, a hashtable stores two values that form an element − the key and the value. In a hashtable, the keys are unique and cannot be null. The values can be null and duplicated. The System.Collections namespace provides the Hashtable class with various constructors, methods, and properties to perform operations on hashtable objects. This article demonstrates how to retrieve a key from a hashtable collection based on a specific value. ... Read More

How to get all the combinations of the keypad value in a mobile by backtracking using C#?

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

388 Views

The problem of generating all possible letter combinations from mobile keypad digits can be solved efficiently using backtracking. This approach explores all possible paths by making choices, exploring them recursively, and backtracking when a complete combination is formed. On a traditional mobile keypad, each digit from 2-9 corresponds to a set of letters. The goal is to find all possible combinations when given a sequence of digits. Mobile Keypad Mapping 2 ABC 3 DEF 4 ... Read More

Advertisements