Csharp Articles

Page 29 of 196

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 182 Views

To get the third element of a Tuple in C#, you use the Item3 property. Tuples in C# provide indexed properties (Item1, Item2, Item3, etc.) to access their elements by position. Syntax Following is the syntax to access the third element of a tuple − var thirdElement = tuple.Item3; You can also create tuples using the generic Tuple class or the Tuple.Create() method − var tuple1 = new Tuple(10, 20, 30); var tuple2 = Tuple.Create(10, 20, 30); Using Item3 Property The Item3 property directly returns the third element of ...

Read More

Remove a range of elements from the ArrayList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 198 Views

The ArrayList class in C# provides the RemoveRange() method to remove a range of elements from the collection. This method is useful when you need to delete multiple consecutive elements efficiently in a single operation. Syntax Following is the syntax for the RemoveRange() method − public virtual void RemoveRange(int index, int count) Parameters index − The zero-based starting index of the range of elements to remove. count − The number of elements to remove. RemoveRange(index, count) Visual ...

Read More

Remove all elements from the SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 197 Views

To remove all elements from a SortedSet in C#, use the Clear() method. This method removes all elements from the SortedSet collection and resets the count to zero. Syntax Following is the syntax for the Clear() method − sortedSetName.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It simply removes all elements from the SortedSet. SortedSet.Clear() Operation Before Clear() {"AB", "BC", "CD", "EF"} Count = 4 ...

Read More

Check if a HashSet is a proper superset of the specified collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 174 Views

The IsProperSupersetOf() method in C# checks if a HashSet is a proper superset of the specified collection. A proper superset means the HashSet contains all elements of the other collection plus at least one additional element. Syntax Following is the syntax for using the IsProperSupersetOf() method − public bool IsProperSupersetOf(IEnumerable other) Parameters other − The collection to compare with the current HashSet. Return Value Returns true if the HashSet is a proper superset of the specified collection; otherwise, false. Proper Superset Relationship ...

Read More

Remove all entries from the ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 157 Views

The ListDictionary class in C# provides the Clear() method to remove all key-value pairs from the collection. This method is useful when you need to empty the entire dictionary without creating a new instance. Syntax Following is the syntax for the Clear() method − listDictionary.Clear(); Parameters The Clear() method takes no parameters. Return Value The method returns void and modifies the existing ListDictionary by removing all entries. Using Clear() Method Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public ...

Read More

Remove all objects from the Queue in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 178 Views

To remove all objects from a Queue in C#, use the Clear() method. This method removes all elements from the Queue and resets its count to zero. The Queue class provides this built-in method for efficient bulk removal of all elements. Syntax Following is the syntax for the Clear() − queue.Clear(); Where queue is the Queue object from which all elements will be removed. Using Clear() Method Example 1 The following example demonstrates clearing a Queue containing string elements − using System; using System.Collections.Generic; public class Demo { ...

Read More

Get an enumerator that iterates through the HybridDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 166 Views

The HybridDictionary class in C# provides the GetEnumerator() method to iterate through its key-value pairs. This method returns an IDictionaryEnumerator object that allows you to traverse the collection efficiently. You can also use foreach loops to iterate through a HybridDictionary. Syntax Following is the syntax for getting an enumerator from a HybridDictionary − IDictionaryEnumerator enumerator = hybridDict.GetEnumerator(); The enumerator provides these key properties − enumerator.Key // Current key enumerator.Value // Current value enumerator.Entry // Current DictionaryEntry HybridDictionary Enumeration ...

Read More

Get an ICollection containing the values in ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 196 Views

The ListDictionary class in C# provides a Values property that returns an ICollection containing all the values stored in the dictionary. This is useful when you need to iterate through or manipulate only the values without accessing the keys. Syntax Following is the syntax to get the values collection from a ListDictionary − ICollection values = listDictionary.Values; Return Value The Values property returns an ICollection object that contains all the values in the ListDictionary. The collection maintains the same order as the original dictionary entries. Using Values Property with Device Names ...

Read More

Get an enumerator that iterates through the ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 193 Views

To get an enumerator that iterates through the ListDictionary, you can use the GetEnumerator() method, which returns an IDictionaryEnumerator. This allows you to iterate through the key-value pairs in the dictionary using a while loop or foreach loop. The ListDictionary is a specialized collection class that implements a dictionary using a singly linked list, making it efficient for small collections (typically 10 or fewer elements). Syntax Following is the syntax for getting an enumerator from a ListDictionary − IDictionaryEnumerator enumerator = listDictionary.GetEnumerator(); while (enumerator.MoveNext()) { // Access enumerator.Key and enumerator.Value } ...

Read More

Get an enumerator that iterates through the SortedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 181 Views

The SortedDictionary class in C# provides the GetEnumerator() method to iterate through its key-value pairs. This method returns an IDictionaryEnumerator that allows you to traverse the collection in ascending order of keys. Syntax Following is the syntax for getting an enumerator from a SortedDictionary − IDictionaryEnumerator enumerator = sortedDictionary.GetEnumerator(); To iterate through the enumerator − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Return Value The GetEnumerator() method returns an IDictionaryEnumerator object that provides access to the key-value ...

Read More
Showing 281–290 of 1,951 articles
« Prev 1 27 28 29 30 31 196 Next »
Advertisements