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
Articles by AmitDiwan
Page 204 of 840
Capacity of a SortedList in C#
The Capacity property of a SortedList in C# represents the maximum number of key-value pairs that the SortedList can hold without needing to resize its internal storage. This is different from the Count property, which shows the actual number of elements currently stored. When elements are added to a SortedList, the capacity automatically grows to accommodate new items. The capacity typically doubles when the current capacity is exceeded, following a geometric growth pattern to optimize performance. Syntax Following is the syntax to get the capacity of a SortedList − int capacity = sortedList.Capacity; ...
Read MoreQueue.Clear Method in C#
The Queue.Clear() method in C# is used to remove all elements from a Queue collection. This method provides an efficient way to empty the entire queue in a single operation, setting the count to zero. Syntax Following is the syntax for the Clear() method − public void Clear(); Parameters The Clear() method does not take any parameters. Return Value The method does not return any value. It is a void method that modifies the queue in place. Queue.Clear() Operation ...
Read MoreQueue.Clone() Method in C#
The Queue.Clone() method in C# is used to create a shallow copy of the Queue. This method returns a new Queue object that contains references to the same elements as the original Queue, but the Queue structure itself is independent. Syntax Following is the syntax for the Queue.Clone() method − public virtual object Clone(); Return Value The method returns an object that represents a shallow copy of the Queue. You need to cast it back to Queue type to use it as a Queue. Understanding Shallow Copy A shallow copy means ...
Read MoreQueue.Contains() Method in C#
The Queue.Contains() method in C# is used to determine whether a specific element exists in the Queue. It returns true if the element is found, otherwise false. This method performs a linear search through the queue elements. Syntax Following is the syntax for the Queue.Contains() method − public bool Contains(T item); Parameters item − The object to locate in the Queue. The value can be null for reference types. Return Value Returns true if the item is found in the Queue; otherwise, false. ...
Read MoreBitConverter Class in C#
The BitConverter class in C# provides static methods to convert base data types to byte arrays and vice versa. It handles the conversion between different data types and their byte representations, making it essential for low-level data manipulation, file I/O, and network communication. Key Methods Method Description GetBytes(Boolean) Returns the specified Boolean value as a byte array. GetBytes(Char) Returns the specified Unicode character value as an array of bytes. GetBytes(Double) Returns the specified double-precision floating-point value as an array of bytes. GetBytes(Int32) Returns the specified ...
Read MoreCheck if a HashSet and a specified collection share common element in C#
To check if a HashSet and a specified collection share a common element, we use the Overlaps() method in C#. This method returns true if the HashSet shares at least one element with the specified collection, and false otherwise. Syntax Following is the syntax for the Overlaps() method − public bool Overlaps(IEnumerable other) Parameters other − The collection to compare with the current HashSet. Return Value Returns true if the HashSet and the specified collection share at least one common element; otherwise, false. Using Overlaps() with Integer HashSets ...
Read MoreCheck if SortedSet and a specified collection share common elements in C#
To check if a SortedSet and a specified collection share common elements in C#, you can use the Overlaps() method. This method returns true if the SortedSet shares at least one element with the specified collection, otherwise it returns false. Syntax Following is the syntax for using the Overlaps() method − public bool Overlaps(IEnumerable other) Parameters other − The collection to compare with the current SortedSet. It can be any collection that implements IEnumerable. Return Value The method returns true if the SortedSet shares at least one element with ...
Read MoreCheck if a value is in LinkedList in C#
To check if a value exists in a LinkedList in C#, you can use the Contains() method. This method performs a linear search through the linked list and returns true if the specified value is found, or false otherwise. Syntax Following is the syntax for the Contains() method − public bool Contains(T item) Parameters item − The value to locate in the LinkedList. Return Value Returns true if the item is found in the LinkedList; otherwise, false. LinkedList.Contains() Method ...
Read MoreCheck if an array contains the elements that match the specified conditions in C#
To check if an array contains elements that match specific conditions in C#, we can use the Array.Exists() method. This method returns true if at least one element in the array matches the specified condition, and false otherwise. Syntax Following is the syntax for Array.Exists() method − public static bool Exists(T[] array, Predicate match); Parameters array − The one-dimensional array to search. match − The predicate that defines the conditions of the elements to search for. Return Value Returns true if at least one element ...
Read MoreCheck if an Array has fixed size or not in C#
In C#, all arrays have a fixed size once they are created. You cannot change the length of an array after initialization. To check if an array has a fixed size, use the IsFixedSize property, which always returns true for arrays. Syntax Following is the syntax to check if an array has fixed size − bool isFixed = arrayName.IsFixedSize; Using IsFixedSize Property Example using System; public class Demo { public static void Main() { string[] products = new ...
Read More