Server Side Programming Articles

Page 3 of 2110

HybridDictionary Class in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 239 Views

The HybridDictionary class implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large. This provides optimal performance for both small and large collections by leveraging the strengths of each underlying data structure. The HybridDictionary automatically switches from ListDictionary to Hashtable when the number of elements exceeds a certain threshold (typically around 10 items), making it ideal for scenarios where the collection size is unpredictable. HybridDictionary Internal Structure Small Collection ListDictionary Linear search ...

Read More

ListDictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 456 Views

The ListDictionary class in C# implements the IDictionary interface using a singly linked list. It is optimized for small collections and is recommended for collections that typically contain fewer than 10 items. For larger collections, it's better to use Hashtable or Dictionary for better performance. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dict = new ListDictionary(); dict.Add(key, value); Key Properties Property Description Count Gets the number of key/value pairs contained in the ListDictionary. IsFixedSize Gets a value indicating whether the ...

Read More

Difference between Class and Structure in C#

Nitin Sharma
Nitin Sharma
Updated on 17-Mar-2026 1K+ Views

In C#, both classes and structures are used to define data types and hold data. While they appear similar in functionality, they have fundamental differences in how they store and manage data. Classes are reference types that provide more flexibility and advanced features, while structures are value types designed for simple data storage with better performance in certain scenarios. Understanding these differences is crucial for choosing the right type for your specific use case and writing efficient C# code. Syntax Following is the syntax for declaring a class − public class ClassName { ...

Read More

Difference between SortedList and SortedDictionary in C#

Nitin Sharma
Nitin Sharma
Updated on 17-Mar-2026 967 Views

Both SortedList and SortedDictionary in C# are generic collections that store key-value pairs in sorted order based on the key. However, they differ significantly in their internal implementation, memory usage, and performance characteristics. Understanding these differences helps you choose the right collection for your specific use case based on performance requirements and usage patterns. Syntax Following is the syntax for declaring a SortedList − SortedList sortedList = new SortedList(); Following is the syntax for declaring a SortedDictionary − SortedDictionary sortedDictionary = new SortedDictionary(); Key Differences ...

Read More

What is the difference between Select and SelectMany in Linq C#?

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

The Select and SelectMany operators in LINQ C# serve different purposes for data projection. Select produces one result value for every source element, while SelectMany belongs to Projection Operators category and is used to project each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence. Syntax Following is the syntax for Select operator − IEnumerable Select( this IEnumerable source, Func selector ) Following is the syntax for SelectMany operator − IEnumerable SelectMany( this IEnumerable source, ...

Read More

What are union, intersect and except operators in Linq C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 706 Views

LINQ set operators in C# allow you to perform set-based operations on collections. The three primary set operators are Union, Intersect, and Except, which enable you to combine, find common elements, and identify differences between sequences. These operators work with any IEnumerable collections and return distinct results by default, making them useful for data manipulation and filtering operations. Syntax Following is the syntax for the three LINQ set operators − // Union - combines two sequences and removes duplicates var result = sequence1.Union(sequence2); // Intersect - returns common elements from both sequences var result ...

Read More

What is the difference between Foreach and Parallel.Foreach in C#?

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

The foreach loop in C# runs on a single thread and processes items sequentially one by one. In contrast, Parallel.ForEach utilizes multiple threads to process items concurrently, potentially improving performance for CPU-intensive operations on large collections. The key difference is that Parallel.ForEach can distribute work across multiple threads, while the standard foreach executes on a single thread. To use Parallel.ForEach, you need to import the System.Threading.Tasks namespace. Syntax Following is the syntax for a standard foreach loop − foreach (var item in collection) { // sequential processing } Following is ...

Read More

How to subscribe to an Event in C# and can we have multiple subscribers to one Event in a C#?

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

Events enable a class or object to notify other classes or objects when something of interest occurs. The class that raises the event is called the publisher and the classes that handle the event are called subscribers. An event can have multiple subscribers, and a subscriber can handle multiple events from multiple publishers. Events that have no subscribers are never raised. The publisher determines when an event is raised; the subscribers determine what action is taken in response to the event. Syntax Following is the syntax for declaring an event using EventHandler − public event ...

Read More

How do you do a deep copy of an object in .NET?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 205 Views

A deep copy in C# creates a completely independent copy of an object, including all its nested objects and reference types. Unlike a shallow copy that only copies references, a deep copy duplicates the entire object hierarchy, ensuring that changes to the copied object do not affect the original. Deep copying is essential when working with complex objects containing reference types like arrays, lists, or custom objects. Without proper deep copying, modifications to nested objects can unexpectedly affect the original object. Shallow Copy vs Deep Copy Shallow Copy ...

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
Showing 21–30 of 21,091 articles
Advertisements