Csharp Articles

Page 2 of 196

C# Program to Get Key based on Value in Hashtable Collection

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 1K+ Views

A hashtable is a collection in C# that holds items identified as key-value pairs. Unlike other data structures like the stack, queue, or ArrayList that store a single value, a hashtable stores two values that form an element − the key and the value. In a hashtable, the keys are unique and cannot be null. The values can be null and duplicated. The System.Collections namespace provides the Hashtable class with various constructors, methods, and properties to perform operations on hashtable objects. This article demonstrates how to retrieve a key from a hashtable collection based on a specific value. ...

Read More

C# Program to Print the Length of the Hashtable

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 892 Views

A Hashtable in C# is a collection that stores key-value pairs, where each key is unique and used to access its corresponding value. Unlike arrays or lists, Hashtables don't have a direct Length property, but we can determine the number of elements using the Count property. The Hashtable class belongs to the System.Collections namespace and organizes elements based on the hash code of their keys. Keys must be unique and non-null, while values can be duplicated or null. Syntax The Count property returns the number of key-value pairs in the Hashtable − public virtual int ...

Read More

How to Convert Hashtable into an Array?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 2K+ Views

The Hashtable collection in C# is a non-generic collection of key-value pairs where each key is unique and non-null, while values can be duplicated or null. Converting a Hashtable into an array is a common operation when you need to work with the data in array format. The Hashtable class provides the CopyTo method to efficiently transfer its elements to an array. This method copies Hashtable items as DictionaryEntry objects to a one-dimensional array. Syntax Following is the syntax for the CopyTo method − public virtual void CopyTo(Array array, int arrayIndex); Parameters ...

Read More

C# BitConverter.ToUInt64 Method

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 361 Views

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 More

TimeSpan.FromTicks() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 440 Views

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 More

Queue.CopyTo() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 306 Views

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 More

Stack.Pop() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

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 More

Remove from the specified index of a SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 234 Views

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 More

OrderedDictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

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 More

Copying the entire ArrayList to 1-D Array starting at the specified index in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 132 Views

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 More
Showing 11–20 of 1,951 articles
« Prev 1 2 3 4 5 196 Next »
Advertisements