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
Csharp Articles
Page 34 of 196
Get the number of key/value pairs in the StringDictionary in C#
The StringDictionary class in C# provides the Count property to get the number of key/value pairs stored in the dictionary. This property is useful for determining the size of the collection and performing operations based on the dictionary's length. Syntax Following is the syntax to get the count of key/value pairs in a StringDictionary − int count = stringDictionary.Count; Return Value The Count property returns an integer representing the number of key/value pairs currently stored in the StringDictionary. Using Count Property with Basic StringDictionary Example using System; using System.Collections; ...
Read MoreRemoving the node at the start of the LinkedList in C#
The LinkedList class in C# provides the RemoveFirst() method to remove the node at the start of the linked list. This method removes the first node and automatically updates the list's internal structure and count. Syntax Following is the syntax for removing the first node from a LinkedList − linkedList.RemoveFirst(); The method throws an InvalidOperationException if the LinkedList is empty. RemoveFirst() Operation One Two Three Four ...
Read MoreGet an ICollection containing the keys in ListDictionary in C#
The ListDictionary class in C# provides a Keys property that returns an ICollection containing all the keys in the dictionary. This is useful when you need to iterate through or process only the keys without accessing their corresponding values. Syntax Following is the syntax to get the keys collection from a ListDictionary − ICollection keys = listDictionary.Keys; Return Value The Keys property returns an ICollection object that contains all the keys from the ListDictionary. The keys are returned in the same order as they were added to the dictionary. Using Keys Property ...
Read MoreGet an ICollection containing the values in HybridDictionary in C#
The HybridDictionary class in C# provides the Values property that returns an ICollection containing all the values in the dictionary. This collection can be used to iterate through values or copy them to an array for further processing. Syntax Following is the syntax to get the values collection from a HybridDictionary − ICollection values = hybridDictionary.Values; To copy values to an array − hybridDictionary.Values.CopyTo(array, startIndex); How It Works The Values property returns an ICollection that contains all the values stored in the HybridDictionary. The order of values may vary ...
Read MoreGet the last node of the LinkedList in C#
In C#, you can get the last node of a LinkedList using the Last property. This property returns a LinkedListNode object representing the last node in the list, or null if the list is empty. Syntax Following is the syntax to get the last node of a LinkedList − LinkedListNode lastNode = linkedList.Last; T lastValue = linkedList.Last.Value; Using Last Property with String LinkedList The following example demonstrates how to access the last node in a string LinkedList − using System; using System.Collections.Generic; public class Demo { public ...
Read MoreGet the maximum value in the SortedSet in C#
The SortedSet class in C# provides the Max property to efficiently retrieve the maximum value from the collection. Since SortedSet maintains elements in sorted order, the maximum element is always the last element in the collection. Syntax Following is the syntax for getting the maximum value from a SortedSet − SortedSet sortedSet = new SortedSet(); T maxValue = sortedSet.Max; Properties Property Description Return Type Max Gets the maximum value in the SortedSet according to the comparer. T Min Gets the minimum value in the ...
Read MoreRemove all objects from the Stack in C#
In C#, the Stack class provides the Clear() method to remove all objects from the Stack. This method efficiently removes every element from the Stack, leaving it empty with a count of zero. Syntax Following is the syntax for removing all objects from a Stack − stack.Clear(); Where stack is the instance of the Stack from which all elements need to be removed. How It Works The Clear()
Read MoreRemoving all entries from HybridDictionary in C#
A HybridDictionary in C# is part of the System.Collections.Specialized namespace that automatically switches between a ListDictionary and Hashtable based on the number of elements. To remove all entries from a HybridDictionary, you use the Clear() method. Syntax Following is the syntax for removing all entries from a HybridDictionary − hybridDictionary.Clear(); Using Clear() Method The Clear() method removes all key-value pairs from the HybridDictionary and sets the Count property to zero − Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() ...
Read MoreGet an enumerator that iterates through the Hashtable in C#
To get an enumerator that iterates through the Hashtable in C#, you use the GetEnumerator() method. This method returns an IDictionaryEnumerator that provides key-value pair access to the hashtable elements. Syntax Following is the syntax for getting an enumerator from a Hashtable − IDictionaryEnumerator enumerator = hashtable.GetEnumerator(); The enumerator provides the following key members − enumerator.MoveNext() // advances to next element, returns bool enumerator.Key // gets current key enumerator.Value // gets current value enumerator.Entry ...
Read MoreGet the minimum value in the SortedSet in C#
The SortedSet class in C# provides built-in properties to efficiently retrieve the minimum and maximum values. The Min property returns the smallest element, while the Max property returns the largest element in the sorted collection. Since SortedSet maintains elements in sorted order, accessing the minimum and maximum values is an O(1) operation, making it very efficient for scenarios where you frequently need these extreme values. Syntax Following is the syntax to get the minimum value from a SortedSet − T minValue = sortedSet.Min; Following is the syntax to get the maximum value from ...
Read More