Csharp Articles

Page 36 of 196

Check if two ListDictionary objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 209 Views

The ListDictionary class in C# is part of the System.Collections.Specialized namespace and provides a simple list-based dictionary implementation. To check if two ListDictionary objects are equal, you can use the Equals() method, which performs reference equality comparison by default. Syntax Following is the syntax for comparing two ListDictionary objects − bool isEqual = listDict1.Equals(listDict2); Understanding ListDictionary Equality The Equals() method in ListDictionary performs reference equality, not content equality. This means it returns true only when both variables refer to the same object in memory, not when they contain the same key-value pairs. ...

Read More

How to get First Element of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 961 Views

A tuple in C# is a data structure that can hold multiple values of different types. To get the first element of a tuple, you use the Item1 property, which provides direct access to the first value stored in the tuple. Syntax Following is the syntax for accessing the first element of a tuple − var tuple = Tuple.Create(value1, value2, value3, ...); var firstElement = tuple.Item1; For value tuples (C# 7.0+), you can also use named elements − var tuple = (first: value1, second: value2, third: value3); var firstElement = tuple.first; ...

Read More

Gets or sets the value of the bit at a specific position in the BitArray in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 201 Views

The BitArray class in C# provides an indexer that allows you to get or set the value of a bit at a specific position. You can access individual bits using either the indexer syntax arr[index] or the Get() and Set() methods. Syntax Following is the syntax for accessing bits in a BitArray − // Using indexer to get/set bits bitArray[index] = true; // Set bit at index bool value = bitArray[index]; // Get bit at index // Using Get() and Set() methods bool value = bitArray.Get(index); // Get bit at index bitArray.Set(index, ...

Read More

Getting an enumerator for a range of elements in the ArrayList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 199 Views

To get an enumerator for a range of elements in the ArrayList, you can use the GetEnumerator(int, int) method. This method allows you to iterate through a specific subset of elements starting from a given index with a specified count. Syntax Following is the syntax for getting an enumerator for a range of elements − IEnumerator enumerator = arrayList.GetEnumerator(startIndex, count); Parameters startIndex − The zero-based starting index of the range. count − The number of elements in the range. Return Value Returns an IEnumerator object that can iterate through ...

Read More

Getting the Type of the Tuple's Element in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 142 Views

In C#, you can get the type of a tuple or its individual elements using the GetType() method and reflection. The GetType() method returns the runtime type of the tuple, which includes information about all its element types. Syntax Following is the syntax to get the type of a tuple − var tuple = Tuple.Create(value1, value2, ...); Type tupleType = tuple.GetType(); To get the type of individual elements, you can use the typeof operator or access element types through reflection − Type elementType = typeof(T); // where T is the element type ...

Read More

Getting the unique identifier for the current managed thread in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 257 Views

To get the unique identifier for the currently managed thread in C#, you can use the Thread.CurrentThread.ManagedThreadId property. This property returns an integer that uniquely identifies each managed thread within the application domain. The ManagedThreadId is different from the operating system thread ID and is specifically designed for managed code debugging and logging purposes. Syntax Following is the syntax for getting the managed thread ID − int threadId = Thread.CurrentThread.ManagedThreadId; For a specific thread object − Thread thread = new Thread(methodName); int threadId = thread.ManagedThreadId; Using ManagedThreadId with Regular ...

Read More

How to add key/value pairs in SortedList in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 330 Views

A SortedList in C# is a collection that stores key/value pairs sorted by keys. The Add() method is the primary way to insert key/value pairs into a SortedList, automatically maintaining sorted order based on the keys. Syntax Following is the syntax for adding key/value pairs to a SortedList − SortedList sortedList = new SortedList(); sortedList.Add(key, value); Parameters key − The key of the element to add. Cannot be null and must be unique. value − The value of the element to add. Can be null. Using ...

Read More

How to create a SortedSet in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

A SortedSet in C# is a collection that maintains its elements in sorted order automatically. It belongs to the System.Collections.Generic namespace and ensures that duplicate elements are not allowed while keeping all elements sorted based on their natural ordering or a custom comparer. Syntax Following is the syntax for creating a SortedSet − SortedSet setName = new SortedSet(); You can also initialize with an existing collection − SortedSet setName = new SortedSet(existingCollection); To use a custom comparer − SortedSet setName = new SortedSet(comparer); Using SortedSet with ...

Read More

Add key and value into StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 290 Views

The StringDictionary class in C# provides a specialized collection for storing string key-value pairs. It is case-insensitive, meaning keys are automatically converted to lowercase when added. The Add() method is used to insert new key-value pairs into the collection. Syntax Following is the syntax for adding key-value pairs to a StringDictionary − StringDictionary dictionary = new StringDictionary(); dictionary.Add(key, value); Parameters key − The key to add to the StringDictionary (string type). value − The value associated with the key (string type). Key Rules ...

Read More

Getting the keys in a SortedList object C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 135 Views

The SortedList class in C# stores key-value pairs sorted by the keys. To retrieve all the keys from a SortedList object, you use the Keys property, which returns an ICollection containing all the keys in sorted order. Syntax Following is the syntax for getting keys from a SortedList − SortedList sortedList = new SortedList(); ICollection keys = sortedList.Keys; The Keys property returns an ICollection that can be iterated using a foreach loop − foreach(string key in keys) { Console.WriteLine(key); } Using Keys Property with String Keys ...

Read More
Showing 351–360 of 1,951 articles
« Prev 1 34 35 36 37 38 196 Next »
Advertisements