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 171 of 840
Check if two LinkedList objects are equal in C#
To check if two LinkedList objects are equal in C#, you need to understand that the Equals() method performs reference equality by default, not content equality. This means it only returns true if both references point to the same object instance. Understanding Reference vs Content Equality The LinkedList class inherits the default Equals() method from Object, which compares object references rather than the actual contents of the lists. LinkedList Equality Types Reference Equality list1.Equals(list2) Returns true only if both ...
Read MoreConvert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#
The Decimal.ToUInt16() method in C# converts a decimal value to its equivalent 16-bit unsigned integer (ushort). This method performs truncation, discarding the fractional part and keeping only the integer portion of the decimal value. Syntax Following is the syntax for the Decimal.ToUInt16() method − public static ushort ToUInt16(decimal value) Parameters value − The decimal number to be converted to a 16-bit unsigned integer. Return Value Returns a ushort (16-bit unsigned integer) that represents the truncated value of the specified decimal. The valid range is 0 to 65, ...
Read MoreCreate a Stack from a collection in C#
To create a Stack from a collection in C#, you can use the Stack constructor that accepts an IEnumerable parameter. This allows you to initialize a stack with elements from arrays, lists, or other collections. Syntax Following is the syntax for creating a Stack from a collection − Stack stack = new Stack(IEnumerable collection); The elements are pushed in the reverse order of the collection enumeration. Creating Stack from Array The following example shows how to create a Stack from an existing array − using System; using System.Collections.Generic; public ...
Read MoreCheck if OrderedDictionary collection is read-only in C#
The OrderedDictionary class in C# provides a collection that maintains the order of key-value pairs while allowing access by both key and index. To check if an OrderedDictionary is read-only, you use the IsReadOnly property. An OrderedDictionary is typically not read-only by default, meaning you can add, modify, and remove elements after creation. However, you can create a read-only wrapper using specific methods. Syntax Following is the syntax to check if an OrderedDictionary is read-only − bool isReadOnly = orderedDictionary.IsReadOnly; Following is the syntax to create a read-only wrapper − OrderedDictionary ...
Read MoreAdding new node or value at the start of LinkedList in C#
To add a new node or value at the start of a LinkedList in C#, you can use the AddFirst() method. This method adds the specified element at the beginning of the LinkedList, making it the first node. Syntax Following is the syntax for adding elements to the beginning of a LinkedList − linkedList.AddFirst(value); You can also add a LinkedListNode object − linkedList.AddFirst(new LinkedListNode(value)); Parameters The AddFirst() method accepts the following parameter − value − The value to add at the beginning of the LinkedList ...
Read MoreCreating a Case-Sensitive HybridDictionary with specified initial size in C#
The HybridDictionary class in C# is a collection that combines the benefits of both ListDictionary and Hashtable. It automatically switches from a ListDictionary (for small collections) to a Hashtable (for larger collections) based on the number of elements. You can create a case-sensitive HybridDictionary with a specified initial size using its constructor. Syntax Following is the syntax for creating a HybridDictionary with specified initial size and case sensitivity − HybridDictionary myDict = new HybridDictionary(initialSize, caseInsensitive); Parameters initialSize − The approximate number of entries that the HybridDictionary can initially contain. ...
Read MoreAdding the elements of the specified collection to the end of the List in C#
The AddRange() method in C# allows you to add all elements from a specified collection to the end of a List. This method is more efficient than adding elements one by one using Add() when you need to append multiple items from an existing collection. Syntax Following is the syntax for the AddRange() method − public void AddRange(IEnumerable collection) Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. Using ...
Read MoreCreating a HybridDictionary with specified initial size in C#
The HybridDictionary class in C# is a special collection that automatically switches between a ListDictionary for small collections and a Hashtable for larger ones. When creating a HybridDictionary with a specified initial size, you can optimize performance by indicating the expected number of elements. The HybridDictionary uses a ListDictionary when the collection is small (typically less than 10 items) and switches to a Hashtable when it grows larger, providing the best performance characteristics for both scenarios. Syntax Following is the syntax for creating a HybridDictionary with specified initial size − HybridDictionary dict = new HybridDictionary(initialSize); ...
Read MoreAdding the specified key and value into HybridDictionary in C#
The HybridDictionary class in C# provides a collection that combines the functionality of a ListDictionary for small collections and a Hashtable for larger collections. It automatically switches between these internal implementations based on the number of elements to optimize performance. HybridDictionary is part of the System.Collections.Specialized namespace and uses a ListDictionary when the collection is small (typically under 10 items) and switches to a Hashtable when it grows larger. Syntax Following is the syntax for adding key-value pairs to a HybridDictionary − HybridDictionary dictionary = new HybridDictionary(); dictionary.Add(key, value); Parameters key ...
Read MoreGet an enumerator that iterates through the SortedList in C#
The SortedList class in C# provides the GetEnumerator() method to retrieve an enumerator that iterates through key-value pairs. This method returns an IDictionaryEnumerator object that allows sequential access to each element in the sorted collection. Syntax Following is the syntax for getting an enumerator from a SortedList − IDictionaryEnumerator enumerator = sortedList.GetEnumerator(); Following is the syntax for iterating using the enumerator − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Return Value The GetEnumerator() method returns an IDictionaryEnumerator ...
Read More