AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 190 of 840

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 160 Views

In C#, you can access the fifth element of a tuple using the Item5 property. This property is available for tuples that contain at least five elements. The Item5 property returns the value stored at the fifth position in the tuple. Syntax Following is the syntax to access the fifth element of a tuple − var fifthElement = tupleVariable.Item5; Where tupleVariable is a tuple with at least five elements, and Item5 retrieves the value at the fifth position. Using Item5 Property Example 1 The following example demonstrates how to access the ...

Read More

Insert into OrderedDictionary with key and value at specified index in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 420 Views

The OrderedDictionary class in C# provides an Insert() method to add key-value pairs at a specific index position. Unlike regular dictionaries, OrderedDictionary maintains the insertion order of elements and allows indexed access. Syntax Following is the syntax for inserting into an OrderedDictionary at a specified index − orderedDict.Insert(index, key, value); Parameters index − The zero-based index at which to insert the key-value pair key − The key of the element to insert value − The value of the element to insert Using Insert() Method The following example demonstrates inserting ...

Read More

Console Class in C#

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

The Console class in C# is part of the System namespace and provides methods and properties for interacting with the console window. It handles standard input, output, and error streams for console applications, allowing you to control cursor position, colors, buffer size, and other console characteristics. Syntax The Console class provides static properties and methods. Here are the basic syntax patterns − Console.PropertyName = value; // Setting properties var value = Console.PropertyName; // Getting properties Console.MethodName(parameters); // Calling methods ...

Read More

Queue.Enqueue() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 487 Views

The Queue.Enqueue() method in C# is used to add an object to the end of the Queue. This method follows the FIFO (First In, First Out) principle where elements are added at the rear and removed from the front. Syntax For generic Queue collections − public void Enqueue(T item); For non-generic Queue collections − public virtual void Enqueue(object obj); Parameters item/obj − The object to add to the end of the Queue. The value can be null for reference types. Queue.Enqueue() Operation ...

Read More

Remove the element with the specified key from the Hashtable in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 206 Views

The Hashtable class in C# provides the Remove() method to delete elements with a specified key. This method removes the key-value pair from the hashtable and reduces the count by one. Syntax Following is the syntax for the Remove() method − public virtual void Remove(object key) Parameters key − The key of the element to remove from the Hashtable. Using Remove() to Delete Single Element The following example demonstrates removing a single element from a Hashtable − using System; using System.Collections; public class Demo { ...

Read More

Intersection of SortedSet with a collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 208 Views

The IntersectWith method in C# allows you to find the common elements between a SortedSet and any collection that implements IEnumerable. This method modifies the original SortedSet to contain only elements that exist in both collections. Syntax Following is the syntax for the IntersectWith method − public void IntersectWith(IEnumerable other) Parameters other − The collection to compare with the current SortedSet. How It Works The IntersectWith method performs an in-place intersection operation, meaning it modifies the original SortedSet and removes all elements that are not present in the specified ...

Read More

Search in a SortedList object in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 251 Views

In C#, a SortedList is a collection that maintains key-value pairs sorted by keys. You can search for specific keys or values using built-in methods like ContainsKey() and ContainsValue(). The SortedList automatically keeps elements sorted, making searches efficient. Syntax Following are the key search methods for SortedList − // Check if a key exists bool ContainsKey(object key) // Check if a value exists bool ContainsValue(object value) // Get value by key (returns null if not found) object this[object key] { get; set; } // Get index of a key (-1 if ...

Read More

Console.KeyAvailable() Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 553 Views

The Console.KeyAvailable property in C# is used to check whether a key press is available in the input buffer without blocking the thread. It returns true if a key has been pressed and is waiting to be read, or false if no key press is pending. This property is particularly useful for creating non-blocking input operations where your program can continue executing other tasks while occasionally checking for user input. Syntax Following is the syntax for the Console.KeyAvailable property − public static bool KeyAvailable { get; } Return Value The property returns ...

Read More

Queue.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 216 Views

The Queue.Equals() method in C# is used to determine whether the specified object is equal to the current queue instance. This method performs reference equality comparison, not content comparison, meaning it returns true only if both variables refer to the same queue object in memory. Syntax Following is the syntax for the Queue.Equals() method − public virtual bool Equals(object obj); Parameters obj − The object to compare with the current queue instance. Return Value Returns true if the specified object is the same instance as the current queue; otherwise, ...

Read More

Check if two List objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 479 Views

In C#, there are several ways to check if two List objects are equal. The default Equals() method checks for reference equality, not content equality. For comparing list contents, you need different approaches depending on your specific requirements. Using Equals() for Reference Equality The Equals() method on List objects checks if both variables reference the same object in memory − using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { List list1 = new List { "One", "Two", "Three" }; ...

Read More
Showing 1891–1900 of 8,392 articles
« Prev 1 188 189 190 191 192 840 Next »
Advertisements