AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 174 of 840

How to create a SortedList in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 171 Views

A SortedList in C# is a collection that stores key-value pairs in sorted order based on the keys. It combines the functionality of arrays and hashtables, automatically maintaining elements in ascending order of keys. Unlike regular lists, SortedList provides efficient searching and maintains order without manual sorting. Syntax Following is the syntax for creating a SortedList − SortedList sortedList = new SortedList(); sortedList.Add(key, value); You can also specify initial capacity − SortedList sortedList = new SortedList(capacity); Key Features Automatic Sorting: Elements are automatically sorted by key in ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 184 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

Copying the entire ArrayList to 1-D Array starting at the specified index in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 132 Views

The ArrayList class in C# provides the CopyTo() method to copy all its elements to a one-dimensional array starting at a specified index. This method is useful when you need to transfer data from a dynamic ArrayList to a fixed-size array. Syntax Following is the syntax for the CopyTo() method − public virtual void CopyTo(Array array, int arrayIndex) Parameters array − The one-dimensional array that is the destination of the elements copied from ArrayList. arrayIndex − The zero-based index in the array at which copying begins. ...

Read More

How to create a Stack in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 181 Views

A Stack in C# is a generic collection that follows the Last-In-First-Out (LIFO) principle. Elements are added and removed from the top of the stack. The Stack class is part of the System.Collections.Generic namespace and provides type-safe stack operations. Syntax Following is the syntax for creating a Stack − Stack stackName = new Stack(); Common Stack operations − stack.Push(item); // Add element to top T item = stack.Pop(); // Remove and return top element T item = stack.Peek(); // Return top element without removing bool exists = stack.Contains(item); // ...

Read More

Remove all elements from the SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 199 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

How to get a subset in a SortedSet in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 212 Views

A SortedSet in C# provides the GetViewBetween() method to obtain a subset of elements within a specified range. This method returns a view that contains all elements between the lower and upper bounds, inclusive of both boundaries. Syntax Following is the syntax for getting a subset from a SortedSet − SortedSet subset = sortedSet.GetViewBetween(lowerValue, upperValue); Parameters lowerValue − The lowest desired value in the view (inclusive). upperValue − The highest desired value in the view (inclusive). Return Value The GetViewBetween() method returns a subset view that contains only the ...

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

Copying the HybridDictionary entries to an Array Instance in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 179 Views

The HybridDictionary class in C# provides a CopyTo() method that allows you to copy all dictionary entries to an array of DictionaryEntry objects. This method is useful when you need to convert dictionary data into array format for processing or storage. The HybridDictionary automatically switches between a ListDictionary (for small collections) and a Hashtable (for larger collections) to optimize performance based on the number of elements. Syntax Following is the syntax for copying HybridDictionary entries to an array − hybridDictionary.CopyTo(array, arrayIndex); Parameters array − The one-dimensional array of type DictionaryEntry ...

Read More

Remove all entries from the ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 158 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
Showing 1731–1740 of 8,392 articles
« Prev 1 172 173 174 175 176 840 Next »
Advertisements