C# SortedDictionary.Add() Method

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

242 Views

The SortedDictionary.Add() method in C# is used to add an element with the specified key and value into the SortedDictionary. Unlike regular dictionaries, SortedDictionary maintains elements in sorted order based on the keys. Syntax Following is the syntax for the Add() method − public void Add(TKey key, TValue value); Parameters key − The key of the element to add. Cannot be null. value − The value of the element to add. Can be null if TValue is a reference type. Return Value This method does not return a value. ... Read More

Convert Queue To array in C#

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

399 Views

Converting a queue to an array in C# is accomplished using the ToArray() method, which is available for the Queue generic collection. This method creates a new array containing all elements from the queue in the same order they were added (FIFO - First In, First Out). Syntax Following is the syntax for converting a queue to an array − T[] array = queue.ToArray(); Where T is the type of elements in the queue, and queue is the Queue instance. Return Value The ToArray() method returns a new array of type T[] ... Read More

C# Program to Show the Use of GetEnvironmentVariable() Method of Environment Class

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

8K+ Views

The GetEnvironmentVariable() method of the Environment class in C# is used to retrieve the value of an environment variable. This method is essential for accessing system-wide and user-specific environment variables such as PATH, TEMP, or custom variables set by applications. Syntax Following is the basic syntax for the GetEnvironmentVariable() method − public static string GetEnvironmentVariable(string variable) There is also an overloaded version that accepts an EnvironmentVariableTarget parameter − public static string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target) Parameters variable − A string containing the name of the environment variable. target ... Read More

SortedDictionary.Clear() Method in C#

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

142 Views

The SortedDictionary.Clear() method in C# is used to remove all key-value pairs from the SortedDictionary. This method provides an efficient way to empty the entire collection in a single operation. Syntax Following is the syntax for the Clear() − public void Clear(); Parameters This method takes no parameters. Return Value This method does not return any value (void). Using Clear() Method with Electronic Items The following example demonstrates how Clear() removes all items from the SortedDictionary − using System; using System.Collections.Generic; public class Demo { ... Read More

Convert Stack to array in C#

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

484 Views

Converting a Stack to an array in C# is accomplished using the ToArray() method. This method creates a new array containing all elements from the stack in the same order they would be popped (LIFO - Last In, First Out). The Stack class in C# is part of the System.Collections.Generic namespace and represents a collection that follows the Last In, First Out principle. Syntax Following is the syntax for converting a Stack to an array − Stack stack = new Stack(); T[] array = stack.ToArray(); How It Works The ToArray() method creates ... Read More

Check whether an element is contained in the ArrayList in C#

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

243 Views

The ArrayList.Contains() method in C# checks whether a specific element exists in the ArrayList. This method returns a boolean value − true if the element is found, false otherwise. Syntax Following is the syntax for the Contains() method − public virtual bool Contains(object item) Parameters item − The object to locate in the ArrayList. The value can be null. Return Value Returns true if the item is found in the ArrayList; otherwise, false. Using Contains() with String Elements The following example demonstrates checking for string ... Read More

How to valid DateofBirth using fluent Validation in C# if it exceeds current year?

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

5K+ Views

FluentValidation in C# provides a powerful way to validate model properties using a fluent interface. When validating date of birth, you need to ensure the date doesn't exceed the current year and falls within a reasonable age range. This validation is essential for preventing future dates in birth date fields and ensuring data integrity in applications dealing with user registration or profile management. Syntax Following is the syntax for creating a date of birth validation rule using FluentValidation − RuleFor(p => p.DateOfBirth) .Must(BeAValidAge) .WithMessage("Invalid {PropertyName}"); ... Read More

Double.IsInfinity() Method in C#

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

160 Views

The Double.IsInfinity() method in C# is used to determine whether a double-precision floating-point number represents positive or negative infinity. This method returns true if the specified number evaluates to either PositiveInfinity or NegativeInfinity, and false otherwise. Infinity values in C# occur when mathematical operations exceed the range of double values, such as dividing a non-zero number by zero or performing calculations that result in overflow. Syntax Following is the syntax for the Double.IsInfinity() method − public static bool IsInfinity(double d); Parameters d − A double-precision floating-point number to test for infinity. ... Read More

Removing the specified node from the LinkedList in C#?

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

170 Views

The LinkedList class in C# provides several methods to remove nodes from the linked list. You can remove nodes by value using Remove() method or remove specific node references using Remove(LinkedListNode). Syntax Following are the different syntaxes for removing nodes from a LinkedList − // Remove by value (removes first occurrence) bool Remove(T value) // Remove specific node void Remove(LinkedListNode node) // Remove first node void RemoveFirst() // Remove last node void RemoveLast() Return Value The Remove(T value) method returns true if the element is successfully removed; otherwise, false. Other ... Read More

Uri.IsHexEncoding() Method in C#

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

122 Views

The Uri.IsHexEncoding() method in C# determines whether a character at a specific position in a string is hexadecimal encoded. This method is useful when working with URIs that contain percent-encoded characters, where hexadecimal encoding follows the pattern %XX (a percent sign followed by two hexadecimal digits). Syntax Following is the syntax − public static bool IsHexEncoding(string pattern, int index); Parameters pattern − The string to check for hexadecimal encoding. index − The zero-based position in the pattern where the check should begin. Return Value Returns ... Read More

Advertisements