Articles on Trending Technologies

Technical articles with clear explanations and examples

Check if two StringCollection objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 210 Views

In C#, checking if two StringCollection objects are equal is not as straightforward as it might seem. The default Equals() method only checks for reference equality, not content equality. This means two collections with identical elements will return false unless they reference the same object. Understanding StringCollection Equality The StringCollection class inherits the default Equals() method from Object, which performs reference comparison. To check for content equality, you need to implement custom comparison logic. StringCollection Equality Types Reference Equality strCol1.Equals(strCol2) Returns true only if ...

Read More

How to perform a specified action on each element of the List in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 289 Views

In C#, you can perform a specified action on each element of a List using the ForEach() method. This method executes a delegate function on every element in the list, making it convenient for applying transformations, calculations, or operations without manually iterating through the collection. Syntax Following is the syntax for using List.ForEach() method − list.ForEach(Action action); Where action is a delegate that takes one parameter of type T and returns void. Parameters action − The Action delegate to perform on each element of the list. Using ForEach() with ...

Read More

Why the error Collection was modified; enumeration operation may not execute occurs and how to handle it in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 21K+ Views

This error occurs when you modify a collection (such as adding or removing items) while iterating through it with a foreach loop or enumerator. The .NET runtime throws this exception to prevent unpredictable behavior and maintain collection integrity. Why This Error Occurs When you use foreach, it creates an internal enumerator that tracks the collection's state. If the collection is modified during iteration, the enumerator detects this change and throws an InvalidOperationException to prevent data corruption or infinite loops. Collection Modification During Iteration Original Collection: [Item1, Item2, Item3] ...

Read More

Check if two StringDictionary objects are equal or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 212 Views

The StringDictionary class in C# is a specialized collection that stores key-value pairs as strings. When comparing two StringDictionary objects for equality, it's important to understand that the default Equals()

Read More

How to play Beep sound through Console in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 369 Views

The Console.Beep() method in C# is used to play a beep sound through the system speaker. This method is particularly useful for providing audio feedback in console applications or alerting users to specific events. Syntax The Console.Beep() method has two overloads − Console.Beep(); Console.Beep(int frequency, int duration); Parameters frequency − The frequency of the beep in hertz (Hz). Must be between 37 and 32767. duration − The duration of the beep in milliseconds. Using Console.Beep() Without Parameters The parameterless Console.Beep() method plays a default beep sound ...

Read More

How to convert byte array to string in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 20K+ Views

In C#, converting a byte array to a string requires understanding character encoding. Every string has a character set and encoding that tells the computer how to interpret raw bytes into characters. The Encoding class provides various methods to decode byte arrays into strings. The most common approach is using the Encoding.GetString() method, which decodes all bytes in a specified byte array into a string. Several encoding schemes are available such as UTF8, Unicode, UTF32, and ASCII. Syntax Following is the basic syntax for converting byte array to string − string result = Encoding.EncodingType.GetString(byteArray); ...

Read More

Get or set the value associated with specified key in SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 161 Views

In C#, the SortedList collection allows you to get or set values using the indexer syntax with square brackets. The indexer property list[key] provides both read and write access to values associated with specific keys in the sorted list. Syntax Following is the syntax for getting a value from SortedList − object value = sortedList[key]; Following is the syntax for setting a value in SortedList − sortedList[key] = value; If the key exists, it updates the value. If the key doesn't exist, it adds a new key-value pair. Getting ...

Read More

How to fetch a property value dynamically in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 7K+ Views

We can use Reflection to fetch a property value dynamically in C#. Reflection provides objects of type Type that describe assemblies, modules, and types, allowing us to dynamically access and manipulate object properties at runtime without knowing them at compile time. The System.Reflection namespace and System.Type class work together to enable dynamic property access through methods like GetProperty() and GetValue(). Syntax Following is the syntax for getting a property value dynamically − Type type = typeof(ClassName); PropertyInfo property = type.GetProperty("PropertyName"); object value = property.GetValue(instanceObject, null); Following is the syntax for setting a property ...

Read More

C# Program to Reverse a Number

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 7K+ Views

Reversing a number is a fundamental programming problem where we reverse the digits of an integer. For example, reversing 12345 gives 54321. This article explores different approaches to reverse a number in C#. Problem Description Given an integer, we need to reverse its digits and return the reversed number. The process involves extracting digits from right to left and reconstructing them from left to right. Examples Input: 12345 Output: 54321 Explanation: The digits are reversed from their original order. Input: 8299 Output: 9928 Explanation: The digits 8, 2, 9, 9 become 9, 9, 2, 8. ...

Read More

C# Program to Return Quadrant in which the Coordinate Lie

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

The Cartesian coordinate system is divided into four quadrants based on the signs of x and y coordinates. In this article, we will learn how to determine which quadrant a given point lies in using C#. Understanding Quadrants The coordinate plane is divided into four regions called quadrants − Quadrant I: x > 0 and y > 0 (both positive) Quadrant II: x < 0 and y > 0 (x negative, y positive) Quadrant III: x < 0 and y < 0 (both negative) Quadrant IV: x > 0 and y < 0 (x positive, y ...

Read More
Showing 9711–9720 of 61,297 articles
« Prev 1 970 971 972 973 974 6130 Next »
Advertisements