Server Side Programming Articles

Page 710 of 2109

Getting index of the specified value in a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 152 Views

To get the index of a specified value in a SortedList object, C# provides the IndexOfValue() method. This method searches for the first occurrence of the specified value and returns its zero-based index position. Syntax Following is the syntax for the IndexOfValue() method − public virtual int IndexOfValue(object value); Parameters value − The value to locate in the SortedList. The value can be null. Return Value The method returns an integer representing the zero-based index of the first occurrence of the value. If the value is not found, it ...

Read More

Getting the index of the specified key in a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 340 Views

To get the index of a specified key in a SortedList object, use the IndexOfKey() method. This method returns the zero-based index of the key within the sorted collection, or -1 if the key is not found. Syntax Following is the syntax for the IndexOfKey() method − public virtual int IndexOfKey(object key) Parameters key − The key to locate in the SortedList object. Return Value Returns the zero-based index of the key parameter if found; otherwise, returns -1. Example The following example demonstrates how to find the ...

Read More

Getting the key at the specified index of a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 159 Views

The SortedList class in C# maintains its elements in sorted order by key. To get the key at a specified index, use the GetKey() method. Since SortedList automatically sorts elements alphabetically by key, the index positions correspond to the sorted order, not the insertion order. Syntax Following is the syntax for getting a key at the specified index − public virtual object GetKey(int index) Parameters index − The zero-based index of the key to get. Return Value Returns the key at the specified index of the SortedList ...

Read More

Add element to SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 236 Views

The SortedSet class in C# provides a way to store unique elements in sorted order. To add elements to a SortedSet, you use the Add() method, which automatically maintains the sorted order and prevents duplicate entries. Syntax Following is the syntax for adding elements to a SortedSet − SortedSet sortedSet = new SortedSet(); bool added = sortedSet.Add(element); Parameters element − The element to add to the SortedSet. Return Value The Add() method returns a bool value: true − If the element was successfully added (not a duplicate). false ...

Read More

Add key and value into OrderedDictionary collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 246 Views

The OrderedDictionary collection in C# maintains the insertion order of key-value pairs, combining features of both hashtables and arrays. To add key-value pairs, use the Add() method which accepts the key and value as parameters. OrderedDictionary is part of the System.Collections.Specialized namespace and allows access to elements both by key and by index, making it useful when you need to preserve insertion order. Syntax Following is the syntax for adding key-value pairs to an OrderedDictionary − OrderedDictionary dict = new OrderedDictionary(); dict.Add(key, value); Parameters key − The key of the element ...

Read More

Remove the specified element from a HashSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 501 Views

A HashSet in C# is a collection that stores unique elements without any specific order. To remove a specified element from a HashSet, you use the Remove() method, which returns true if the element was found and removed, or false if the element was not present. Syntax The Remove() method follows this syntax − public bool Remove(T item) Parameters item − The element to remove from the HashSet. Return Value The method returns true if the element was successfully found and removed; otherwise, false. ...

Read More

Remove a range of elements from the List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 534 Views

The RemoveRange() method in C# allows you to remove multiple elements from a List at once by specifying a starting index and the number of elements to remove. This is more efficient than removing elements one by one. Syntax Following is the syntax for the RemoveRange() method − public 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 starting from the specified index. RemoveRange(1, 3) Example ...

Read More

Removing first occurrence of object from Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 186 Views

The Collection.Remove() method in C# removes the first occurrence of a specified object from the collection. This method searches through the collection sequentially and removes only the first matching element it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for the Remove() method − public bool Remove(T item) Parameters item: The object to remove from the collection. The value can be null for reference types. Return Value The method returns a bool value − true: If the item was successfully found and removed false: ...

Read More

Removing first occurrence of specified value from LinkedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 350 Views

The LinkedList.Remove(T) method in C# removes the first occurrence of the specified value from a LinkedList. This method searches the LinkedList from the beginning and removes only the first matching node it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for removing the first occurrence of a specified value − public bool Remove(T value) Parameters value: The value to remove from the LinkedList. Return Value Returns true if the element is successfully found and removed; otherwise, false. This method also returns false if the value was ...

Read More

Get the number of key/value pairs contained in ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 182 Views

To get the number of key/value pairs contained in ListDictionary, you use the Count property. The ListDictionary class in C# is part of the System.Collections.Specialized namespace and is optimized for small collections with typically fewer than 10 elements. The Count property returns an integer representing the total number of key/value pairs currently stored in the ListDictionary. Syntax Following is the syntax for getting the count of key/value pairs in ListDictionary − ListDictionary listDict = new ListDictionary(); int count = listDict.Count; Using Count Property Example using System; using System.Collections; using System.Collections.Specialized; ...

Read More
Showing 7091–7100 of 21,090 articles
« Prev 1 708 709 710 711 712 2109 Next »
Advertisements