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
Articles by AmitDiwan
Page 190 of 840
How to get Fifth Element of the Tuple in C#?
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 MoreInsert into OrderedDictionary with key and value at specified index in C#
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 MoreConsole Class in C#
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 MoreQueue.Enqueue() Method in C#
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 MoreRemove the element with the specified key from the Hashtable in C#
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 MoreIntersection of SortedSet with a collection in C#
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 MoreSearch in a SortedList object in C#
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 MoreConsole.KeyAvailable() Property in C#
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 MoreQueue.Equals() Method in C#
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 MoreCheck if two List objects are equal in C#
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