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
Server Side Programming Articles
Page 714 of 2109
Check if a SortedList is read-only in C#
The SortedList class in C# provides the IsReadOnly property to determine whether the collection can be modified. A read-only SortedList cannot have elements added, removed, or modified after creation. Syntax Following is the syntax to check if a SortedList is read-only − bool isReadOnly = sortedList.IsReadOnly; Return Value The IsReadOnly property returns a bool value − true if the SortedList is read-only false if the SortedList allows modifications Example The following example demonstrates how to check if a SortedList is read-only − ...
Read MoreRemoving the specified element from the List in C#
The List.Remove() method in C# removes the first occurrence of a specified element from the list. It returns true if the element was successfully removed, or false if the element was not found in the list. Syntax Following is the syntax for the Remove() method − public bool Remove(T item) Parameters item − The element to remove from the list Return Value Returns true if the element is successfully found and removed; otherwise, false. Using Remove() with String Lists The following example demonstrates removing a string element ...
Read MoreCheck if SortedDictionary contains the specified key or not in C#
To check if a SortedDictionary contains a specified key, C# provides the ContainsKey() method. This method returns true if the key exists in the dictionary, otherwise false. The SortedDictionary maintains its elements in sorted order by key, making key lookups efficient with O(log n) time complexity. Syntax Following is the syntax for the ContainsKey() method − public bool ContainsKey(TKey key) Parameters key − The key to locate in the SortedDictionary. Return Value Returns true if the SortedDictionary contains an element with the specified key; otherwise, false. Using ContainsKey() ...
Read MoreAdding an element to the List in C#
The List class in C# provides the Add() method to add elements to the end of the list. This method is part of the System.Collections.Generic namespace and allows you to dynamically grow the list by appending new elements. Syntax Following is the syntax for adding an element to a List − list.Add(element); Parameters element − The object to be added to the end of the List. The value can be null for reference types. Adding String Elements to List using System; using System.Collections.Generic; public class Demo { ...
Read MoreAdding new node or value at the end of LinkedList in C#
The LinkedList class in C# provides the AddLast() method to add new nodes or values at the end of the linked list. This method maintains the sequential order and automatically updates the internal node structure. Syntax Following is the syntax for adding elements at the end of a LinkedList − LinkedList list = new LinkedList(); list.AddLast(value); The AddLast() method has two overloads − public LinkedListNode AddLast(T value) public void AddLast(LinkedListNode node) Parameters value − The value to add at the end of the LinkedList. node − The LinkedListNode ...
Read MoreCheck if HybridDictionary has fixed size in C#
The HybridDictionary class in C# is a specialized collection that combines the performance benefits of both ListDictionary and Hashtable. To check if a HybridDictionary has a fixed size, you can use the IsFixedSize property, which returns false for standard HybridDictionary instances since they are dynamically resizable. Syntax Following is the syntax for checking if a HybridDictionary has a fixed size − bool isFixed = hybridDictionary.IsFixedSize; HybridDictionary Properties The HybridDictionary class provides several properties to check its characteristics − IsFixedSize − Returns true if the dictionary has a fixed size; otherwise, false ...
Read MoreGet the number of nodes contained in LinkedList in C#
In C#, the LinkedList class provides the Count property to get the number of nodes contained in the LinkedList. This property returns an integer representing the total number of elements in the collection. Syntax Following is the syntax to get the count of nodes in a LinkedList − int count = linkedList.Count; Return Value The Count property returns an int value representing the number of nodes currently present in the LinkedList. LinkedList Node Count Node A Node B ...
Read MoreGetting an enumerator that iterates through HashSet in C#
A HashSet in C# is a collection that stores unique elements without duplicates. To iterate through a HashSet, you can use the GetEnumerator() method which returns an enumerator object, or use a foreach loop for simpler iteration. The HashSet.Enumerator provides manual control over iteration using MoveNext() and Current properties, while foreach handles enumeration automatically behind the scenes. Syntax Following is the syntax for getting an enumerator from a HashSet − HashSet.Enumerator enumerator = hashSet.GetEnumerator(); while (enumerator.MoveNext()) { T current = enumerator.Current; // use current element } ...
Read MoreCheck if ListDictionary contains a specific key in C#
The ListDictionary class in C# provides the Contains() method to check if a specific key exists in the collection. This method returns true if the key is found, otherwise false. ListDictionary is part of the System.Collections.Specialized namespace and is optimized for small collections. Syntax Following is the syntax for using the Contains() − public bool Contains(object key); Parameters key − The object to locate in the ListDictionary. Return Value Returns true if the ListDictionary contains an element with the specified key; otherwise, false. Using Contains() Method ...
Read MoreCheck if ListDictionary has a fixed size in C#
The ListDictionary class in C# provides the IsFixedSize property to determine whether the dictionary has a fixed size. A ListDictionary is a lightweight collection that stores key-value pairs using a singly linked list implementation, making it ideal for small collections (typically 10 or fewer items). Syntax Following is the syntax for checking if a ListDictionary has a fixed size − bool isFixed = listDictionary.IsFixedSize; Return Value The IsFixedSize property returns a bool value − true − The ListDictionary has a fixed size and cannot grow or shrink false ...
Read More