Programming Articles

Page 37 of 2547

Intersection of SortedSet with a collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 189 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 243 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 536 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 204 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 452 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

Intersection of two HashSets in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 573 Views

The intersection of two HashSets in C# finds the common elements present in both collections. The HashSet class provides the IntersectWith() method to perform this operation efficiently. Syntax Following is the syntax for finding the intersection of two HashSets − hashSet1.IntersectWith(hashSet2); Parameters other − The collection to compare to the current HashSet. Return Value The IntersectWith() method does not return a value. It modifies the current HashSet to contain only the elements that exist in both HashSets. HashSet Intersection ...

Read More

How to check whether a thread is alive or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 642 Views

To check whether a thread is alive or not in C#, you use the IsAlive property of the Thread class. This property returns true if the thread has been started and has not yet terminated normally or been aborted. Syntax Following is the syntax for checking if a thread is alive − bool isAlive = thread.IsAlive; The IsAlive property returns true when the thread is in Running, WaitSleepJoin, or Suspended states, and false when the thread is in Unstarted, Stopped, or Aborted states. Thread State and IsAlive Property ...

Read More

What is the purpose of the StringBuilder class in C#?

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 565 Views

In C#, strings are immutable, meaning you cannot modify a string once it's created. Any modification returns a new string containing the changes, leaving the original intact. The StringBuilder class provides a mutable alternative for efficient string manipulation when you need to perform multiple modifications. String Immutability Example using System; class Program { static void Main(string[] args) { string word = "aaabbbccc"; string newWord = word.Replace('b', 'd'); Console.WriteLine(word); ...

Read More

Console.MoveBufferArea() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 357 Views

The Console.MoveBufferArea() method in C# is used to copy a specified source area of the screen buffer to a specified destination area. This method allows you to move text and formatting from one part of the console window to another without rewriting the content. Syntax Following is the syntax for the Console.MoveBufferArea() method − public static void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop); Parameters sourceLeft − The leftmost column of the source area (0-based index). sourceTop − The topmost row of the source area (0-based index). ...

Read More

Stack.Clone() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 299 Views

The Stack.Clone() method in C# creates a shallow copy of the Stack. This method returns a new Stack object with the same elements as the original, but both stacks remain independent for basic operations like Push and Pop. Syntax Following is the syntax for the Stack.Clone() method − public virtual object Clone(); Return Value The method returns an object that represents a shallow copy of the Stack. You need to cast it back to a Stack type to use it as a Stack. Understanding Shallow Copy A shallow copy means that ...

Read More
Showing 361–370 of 25,467 articles
« Prev 1 35 36 37 38 39 2547 Next »
Advertisements