Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
TimeSpan.Subtract() Method in C#
The TimeSpan.Subtract() method in C# returns a new TimeSpan object whose value is the difference between the current instance and the specified TimeSpan object. This method is useful for calculating time differences in applications dealing with durations and intervals. Syntax Following is the syntax for the TimeSpan.Subtract() method − public TimeSpan Subtract(TimeSpan span); Parameters span − The TimeSpan object to subtract from the current instance. Return Value Returns a new TimeSpan object that represents the time interval difference. If the subtracted value is greater than the current ...
Read MoreCheck whether a Hashtable contains a specific key or not in C#
The Hashtable class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, and false otherwise. Syntax Following is the syntax for checking if a Hashtable contains a specific key − bool result = hashtable.Contains(key); Parameters key − The key to search for in the Hashtable. This parameter is of type Object. Return Value The Contains() method returns a bool value − true if the Hashtable contains the specified ...
Read MoreListDictionary Class in C#
The ListDictionary class in C# implements the IDictionary interface using a singly linked list. It is optimized for small collections and is recommended for collections that typically contain fewer than 10 items. For larger collections, it's better to use Hashtable or Dictionary for better performance. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dict = new ListDictionary(); dict.Add(key, value); Key Properties Property Description Count Gets the number of key/value pairs contained in the ListDictionary. IsFixedSize Gets a value indicating whether the ...
Read MoreC# SortedDictionary.Add() Method
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 MoreConvert Queue To array in C#
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 MoreC# Program to Show the Use of GetEnvironmentVariable() Method of Environment Class
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 MoreSortedDictionary.Clear() Method in C#
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 MoreConvert Stack to array in C#
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 MoreCheck whether an element is contained in the ArrayList in C#
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 MoreHow to valid DateofBirth using fluent Validation in C# if it exceeds current year?
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