AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 192 of 840

How to create a ListDictionary in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 146 Views

A ListDictionary in C# is a specialized collection class from the System.Collections.Specialized namespace that implements IDictionary using a singly linked list. It is optimized for small collections (typically 10 items or fewer) and offers better performance than Hashtable for small datasets. The ListDictionary class is ideal when you need a dictionary-like collection with a small number of elements, as it has lower memory overhead compared to hash-based collections. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dictionary = new ListDictionary(); To add key-value pairs to the ListDictionary − ...

Read More

Searching the index of specified object in Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 192 Views

In C#, you can search for the index of a specified object in a collection using the IndexOf() method. This method returns the zero-based index of the first occurrence of the specified object, or -1 if the object is not found. Syntax The basic syntax for finding the index of an object in a collection − int index = collection.IndexOf(objectToFind); Return Value Returns the zero-based index of the first occurrence of the specified object. Returns -1 if the object is not found in the collection. Using ...

Read More

Console.ReadLine() Method in C#

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

The Console.ReadLine() method in C# is used to read the next line of characters from the standard input stream. It reads input from the user until the Enter key is pressed and returns the input as a string. This method is commonly used in console applications to capture user input for processing. It waits for user input and returns null if the input stream has been redirected and no more lines are available. Syntax Following is the syntax for the Console.ReadLine() method − public static string ReadLine(); Return Value The method returns ...

Read More

Stack.CopyTo() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 155 Views

The Stack.CopyTo() method in C# is used to copy all elements of a Stack to an existing one-dimensional Array, starting at a specified array index. This method is useful when you need to transfer stack data into an array for further processing or storage. Syntax Following is the syntax of the Stack.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 Stack. The Array must have zero-based indexing. index − The zero-based index in ...

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 200 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

Search for an element matching the conditions and return the zero-based index of the last occurrence within the entire List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 257 Views

The FindLastIndex() method in C# searches for an element that matches the conditions defined by a specified predicate and returns the zero-based index of the last occurrence within the entire List. This method is particularly useful when you need to find the rightmost element that satisfies certain criteria. Syntax Following is the syntax for the FindLastIndex() method − public int FindLastIndex(Predicate match) Parameters match − The Predicate delegate that defines the conditions of the element to search for. Return Value Returns the zero-based index of the last ...

Read More

Console.ResetColor() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 443 Views

The Console.ResetColor() method in C# is used to reset the foreground and background console colors to their default values. This method is particularly useful when you have changed the console colors during program execution and want to restore the original appearance. Syntax Following is the syntax for the Console.ResetColor() method − public static void ResetColor(); Parameters This method takes no parameters. Return Value This method returns void (nothing). Using Console.ResetColor() Method The method restores both foreground and background colors to the system defaults. Here's how colors work in console ...

Read More

Queue.ToArray Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 167 Views

The Queue.ToArray() method in C# copies all Queue elements to a new array. This method creates a shallow copy of the queue's elements in the same order (FIFO - First In, First Out). Syntax The syntax for the generic Queue is as follows − public T[] ToArray(); Return Value Returns a new array of type T[] containing copies of the elements from the Queue. The array elements maintain the same order as they would be dequeued from the queue. Queue.ToArray() Process Queue ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 198 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

Get an enumerator that iterates through the SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 157 Views

The SortedSet class in C# provides the GetEnumerator() method to retrieve an enumerator that iterates through the collection in sorted order. This enumerator allows you to manually control the iteration process using MoveNext() and Current properties. Syntax Following is the syntax for getting an enumerator from a SortedSet − SortedSet.Enumerator enumerator = sortedSet.GetEnumerator(); Following is the syntax for using the enumerator to iterate − while (enumerator.MoveNext()) { T currentElement = enumerator.Current; // process currentElement } Using GetEnumerator() with String Elements The following example ...

Read More
Showing 1911–1920 of 8,392 articles
« Prev 1 190 191 192 193 194 840 Next »
Advertisements