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 679 of 2109
How to Get Value from HashTable Collection in C# using Specified Key
A Hashtable is a collection of key-value pairs that provides fast lookup by key. In C#, you can retrieve values from a hashtable using the indexer syntax hashtable[key] or by checking if a key exists using the Contains() method. This is essential for accessing specific data when you know the corresponding key. Syntax Following is the syntax for getting a value from a hashtable using a specified key − // Check if key exists if (hashtable.Contains(key)) { object value = hashtable[key]; } // Direct access (may return null if key doesn't exist) ...
Read MoreHow to Get Hashtable Elements as Sorted Array?
A Hashtable is a non-generic collection of key-value pairs that are arranged according to the hash code of the key. The hashtable optimizes lookups by calculating the hash code of each key and storing it internally. When accessing a particular value, this hash code is matched with the specified key. This hashtable collection is defined in the System.Collections namespace of C#. The class that represents the hashtable collection is the Hashtable class. By default, hashtable collections are unsorted. To get sorted data, we need to extract the elements into an Array and sort them. Why Hashtables Are Unsorted ...
Read MoreC# BitConverter.ToUInt64 Method
The BitConverter.ToUInt64() method in C# converts eight consecutive bytes from a byte array into a 64-bit unsigned integer (ulong). This method is useful when you need to reconstruct numeric values from byte data, such as reading from binary files or network streams. Syntax public static ulong ToUInt64(byte[] value, int startIndex); Parameters value − The byte array containing the bytes to convert. startIndex − The starting position within the byte array (must have at least 8 bytes from this position). Return Value Returns a 64-bit unsigned integer (ulong) formed by eight ...
Read MoreTimeSpan.FromTicks() Method in C#
The TimeSpan.FromTicks() method in C# is used to create a TimeSpan object that represents a specified time duration in ticks. A tick represents one hundred nanoseconds or one ten-millionth of a second, making it the smallest unit of time measurement in .NET. Syntax Following is the syntax for the TimeSpan.FromTicks() method − public static TimeSpan FromTicks(long val); Parameters The method accepts the following parameter − val − A long integer representing the number of ticks. Each tick equals 100 nanoseconds. Return Value Returns a TimeSpan object that represents ...
Read MoreQueue.CopyTo() Method in C#
The Queue.CopyTo() method in C# is used to copy the Queue elements to an existing one-dimensional Array, starting at the specified array index. This method is particularly useful when you need to transfer queue elements into an array while preserving the FIFO (First In, First Out) order. Syntax Following is the syntax for the Queue.CopyTo() method − public virtual void CopyTo(Array arr, int index); Parameters arr − The one-dimensional Array that is the destination of the elements copied from Queue. The Array must have zero-based indexing. index − The ...
Read MoreStack.Pop() Method in C#
The Stack.Pop() method in C# is used to remove and return the object at the top of the Stack. This method follows the LIFO (Last In, First Out) principle, where the most recently added element is the first one to be removed. Syntax Following is the syntax for the Pop() − public virtual object Pop(); Return Value The Pop() method returns the object that was removed from the top of the Stack. If the Stack is empty, it throws an InvalidOperationException. How Stack.Pop() Works Stack.Pop() Operation ...
Read MoreRemove from the specified index of a SortedList in C#
The SortedList class in C# provides the RemoveAt() method to remove a key-value pair from a specified index. The RemoveAt() method removes the element at the specified zero-based index and automatically shifts the remaining elements to fill the gap. Syntax Following is the syntax for the RemoveAt() method − public virtual void RemoveAt(int index) Parameters index − The zero-based index of the element to remove. Key Points The index is zero-based, meaning the first element is at index 0. After removal, all elements at higher indices are shifted ...
Read MoreOrderedDictionary Class in C#
The OrderedDictionary class in C# represents a collection of key/value pairs that maintains insertion order and allows access by both key and index. It combines the functionality of a dictionary with the ordered nature of a list, making it useful when you need to preserve the order of items while still providing fast key-based lookup. Syntax Following is the syntax for creating and using an OrderedDictionary − OrderedDictionary dict = new OrderedDictionary(); dict.Add(key, value); dict[key] = value; // Access by key dict[index] = value; // Access by index ...
Read MoreCopying the entire ArrayList to 1-D Array starting at the specified index in C#
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 MoreHow to get the remaining elements of the Tuple in C#?
The Rest property in C# is used to get the remaining elements of a Tuple when it contains more than 7 elements. Since Tuple can hold a maximum of 8 elements, the 8th position (accessed via the Rest property) contains any additional elements as a nested Tuple. Syntax Following is the syntax for accessing the Rest property of a Tuple − var tuple = Tuple.Create(item1, item2, ..., item7, item8); var restElements = tuple.Rest; How It Works When a Tuple has exactly 8 elements, the Rest property returns the 8th element. When a Tuple ...
Read More