Remove the first occurrence from the StringCollection in C#

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

161 Views

The StringCollection class in C# provides the Remove() method to remove the first occurrence of a specified string from the collection. This method is useful when you need to eliminate duplicate values or specific elements from your string collection. Syntax Following is the syntax for removing the first occurrence from a StringCollection − stringCollection.Remove(string value); Parameters value − The string to remove from the StringCollection. The method removes only the first occurrence if multiple instances exist. Return Value The Remove() does not return a value. It modifies ... Read More

Get the number of key/values pairs contained in OrderedDictionary in C#

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

147 Views

The OrderedDictionary class in C# provides a Count property to get the number of key-value pairs it contains. This property returns an integer value representing the total number of elements in the collection. OrderedDictionary is part of the System.Collections.Specialized namespace and maintains the insertion order of elements while allowing access by both key and index. Syntax Following is the syntax for accessing the Count property − int count = orderedDictionary.Count; Using Count Property with OrderedDictionary Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { ... Read More

How to return the index of first unique character without inbuilt functions using C#?

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

586 Views

Finding the index of the first unique character in a string is a common programming problem. The approach involves using a frequency array to count character occurrences, then traversing the string again to find the first character with a count of 1. The algorithm uses an array of size 256 to accommodate all ASCII characters. First, we count the frequency of each character, then we find the first character that appears exactly once. Algorithm Steps The solution follows these steps − Create an integer array of size 256 to store character frequencies ... Read More

Removing the specified key entry from HybridDictionary in C#

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

206 Views

The HybridDictionary class in C# provides the Remove() method to remove a specified key-value pair from the collection. This method takes the key as a parameter and removes the corresponding entry if it exists. Syntax Following is the syntax for removing a key entry from HybridDictionary − public void Remove(object key); Parameters key − The key of the element to remove from the HybridDictionary. How It Works The Remove()

How to get Fourth Element of the Tuple in C#?

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

132 Views

To get the fourth element of a Tuple in C#, you use the Item4 property. This property provides direct access to the fourth item stored in the tuple, regardless of the tuple's total size. Syntax Following is the syntax for accessing the fourth element of a tuple − var fourthElement = tuple.Item4; The Item4 property returns the value stored at the fourth position in the tuple. Using Item4 with Different Tuple Types Example with 7-Tuple using System; public class Demo { public static void Main(String[] ... Read More

Create a Queue from another collection in C#?

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

148 Views

Creating a Queue from another collection in C# can be accomplished using the Queue constructor that accepts an IEnumerable parameter. This allows you to initialize a new Queue with elements from arrays, lists, other queues, or any collection that implements IEnumerable. Syntax Following is the syntax to create a Queue from another collection − Queue newQueue = new Queue(sourceCollection); Where sourceCollection can be any collection implementing IEnumerable such as arrays, lists, or other queues. Using Queue Constructor with Array Example using System; using System.Collections.Generic; public class Demo { ... Read More

MathF.Atan2() Method in C# with Examples

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

269 Views

The MathF.Atan2() method in C# returns the angle whose tangent is the quotient of two specified floating-point numbers. It calculates the arctangent of y/x and returns the angle in radians between the positive x-axis and the point (x, y). This method is particularly useful for determining the angle of a point in a coordinate system and handles all four quadrants correctly, unlike the regular arctangent function. Syntax Following is the syntax − public static float Atan2(float y, float x); Parameters y − The y-coordinate of a point (numerator). x − The ... Read More

Getting index of the specified value in a SortedList object in C#

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

148 Views

To get the index of a specified value in a SortedList object, C# provides the IndexOfValue() method. This method searches for the first occurrence of the specified value and returns its zero-based index position. Syntax Following is the syntax for the IndexOfValue() method − public virtual int IndexOfValue(object value); Parameters value − The value to locate in the SortedList. The value can be null. Return Value The method returns an integer representing the zero-based index of the first occurrence of the value. If the value is not found, it ... Read More

What are the different ways to find missing numbers in a sorted array without any inbuilt functions using C#?

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

2K+ Views

Finding missing numbers in a sorted array is a common programming problem with multiple efficient solutions. This article explores three different approaches to identify missing numbers without using built-in functions in C#. Each method has its own advantages in terms of time and space complexity, making them suitable for different scenarios depending on your specific requirements. Using Sum Formula (Mathematical Approach) This method uses the mathematical formula n(n+1)/2 to calculate the expected sum of consecutive numbers, then subtracts the actual sum of array elements to find the missing number − using System; public class ... Read More

MathF.Acosh() Method in C# with Examples

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

163 Views

The MathF.Acosh() method in C# returns the hyperbolic arc-cosine (inverse hyperbolic cosine) of a floating-point value. This method is part of the MathF class, which provides mathematical functions for float values with better performance than the double-precision Math class. The hyperbolic arc-cosine is defined for values greater than or equal to 1. For values less than 1, the method returns NaN (Not a Number). Syntax Following is the syntax for the MathF.Acosh() method − public static float Acosh(float val); Parameters val − A floating-point number representing the hyperbolic cosine value. Must ... Read More

Advertisements