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
Csharp Articles
Page 3 of 196
How to get the remaining elements of the Tuple in C#?
The Rest property in C# is used to get the remaining elements of a Tuple when it contains more than 7 elements. Since Tuple can hold a maximum of 8 elements, the 8th position (accessed via the Rest property) contains any additional elements as a nested Tuple. Syntax Following is the syntax for accessing the Rest property of a Tuple − var tuple = Tuple.Create(item1, item2, ..., item7, item8); var restElements = tuple.Rest; How It Works When a Tuple has exactly 8 elements, the Rest property returns the 8th element. When a Tuple ...
Read MoreSortedSet Class in C#
The SortedSet class in C# represents a collection of objects that is maintained in sorted order. Unlike regular sets, SortedSet automatically keeps elements sorted and ensures uniqueness − duplicate elements are not allowed. SortedSet is part of the System.Collections.Generic namespace and provides efficient operations for adding, removing, and searching elements while maintaining the sorted order. Syntax Following is the syntax for creating and using a SortedSet − SortedSet setName = new SortedSet(); setName.Add(element); Key Properties Property Description Comparer Gets the IComparer object that is used ...
Read MoreHybridDictionary Class in C#?
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 MoreListDictionary Class in C#
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 MoreDifference between Class and Structure in C#
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 MoreDifference between SortedList and SortedDictionary in C#
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 MoreWhat is the difference between Select and SelectMany in Linq C#?
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 MoreWhat are union, intersect and except operators in Linq C#?
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 MoreWhat is the difference between Foreach and Parallel.Foreach in C#?
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 MoreHow to subscribe to an Event in C# and can we have multiple subscribers to one Event in a C#?
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