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 by AmitDiwan
Page 188 of 840
C# 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 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 MoreDouble.IsInfinity() Method in C#
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 MoreRemoving the specified node from the LinkedList in C#?
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 MoreUri.IsHexEncoding() Method in C#
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 MoreTimeSpan.Add() Method in C#
The TimeSpan.Add() method in C# returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and the current instance. This method is useful for adding time intervals together, such as combining durations or calculating elapsed time periods. Syntax Following is the syntax for the TimeSpan.Add() method − public TimeSpan Add(TimeSpan span); Parameters span − A TimeSpan object representing the time interval to add to the current TimeSpan instance. Return Value Returns a new TimeSpan object that represents the sum of the current TimeSpan and the specified ...
Read MoreGet the number of elements contained in the Stack in C#
The Count property in C# provides an efficient way to get the number of elements contained in a Stack. This property returns an integer value representing the current number of items stored in the stack. Syntax Following is the syntax for using the Count property − Stack stack = new Stack(); int count = stack.Count; Return Value The Count property returns an int value representing the number of elements in the stack. For an empty stack, it returns 0. Stack Count Property ...
Read More