Articles on Trending Technologies

Technical articles with clear explanations and examples

Check whether the Dictionary contains a specific value or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 576 Views

The Dictionary class in C# provides the ContainsValue() method to check whether a specific value exists in the dictionary. This method returns true if the value is found, otherwise false. Syntax Following is the syntax for the ContainsValue() method − public bool ContainsValue(TValue value); Parameters value − The value to locate in the Dictionary. Return Value Returns true if the Dictionary contains an element with the specified value; otherwise, false. Using ContainsValue() - Value Found The following example demonstrates checking for an existing value in ...

Read More

How to make a method deprecated in C#?

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

The Obsolete Attribute marks elements like classes, methods, properties, fields, delegates, and many others within our code as deprecated or obsolete. The attribute is read at compile time and is used to generate a warning or an error to the developer. This attribute can help if we have ever wanted to make sure programmers use newer versions of methods. It also makes it easier when we are transitioning from older methods to newer ones. Marking an item as obsolete warns users that program elements will be removed in future versions of the code base. This attribute is found ...

Read More

What is Interface segregation principle and how to implement it in C#?

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

The Interface Segregation Principle (ISP) is the fourth principle of SOLID design principles. It states that clients should not be forced to depend upon interfaces that they don't use. Instead of creating one large interface with many methods, it's better to create multiple smaller, focused interfaces that serve specific purposes. This principle promotes high cohesion and loose coupling by ensuring that classes only implement the methods they actually need, making the code more maintainable and flexible. Syntax Following is the syntax for creating segregated interfaces − public interface ISpecificInterface { // Only ...

Read More

SortedDictionary.Values Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 287 Views

The SortedDictionary.Values property in C# is used to get a collection containing the values in the SortedDictionary. This property returns a ValueCollection that preserves the sorted order of the original dictionary based on the keys. Syntax Following is the syntax for the Values property − public SortedDictionary.ValueCollection Values { get; } Return Value The property returns a SortedDictionary.ValueCollection containing all the values in the sorted dictionary. The values maintain the same order as their corresponding keys in the sorted dictionary. Using Values Property to Iterate Through Values The following example demonstrates ...

Read More

Check if ListDictionary contains a specific key in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 250 Views

The ListDictionary class in C# provides the Contains() method to check if a specific key exists in the collection. This method returns true if the key is found, otherwise false. ListDictionary is part of the System.Collections.Specialized namespace and is optimized for small collections. Syntax Following is the syntax for using the Contains() − public bool Contains(object key); Parameters key − The object to locate in the ListDictionary. Return Value Returns true if the ListDictionary contains an element with the specified key; otherwise, false. Using Contains() Method ...

Read More

Get the TypeCode for value type UInt64 in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 230 Views

The GetTypeCode() method in C# returns a TypeCode enumeration value that identifies the specific type of a variable. For UInt64 (unsigned 64-bit integer) values, this method always returns TypeCode.UInt64, regardless of the actual numeric value stored. Syntax Following is the syntax for getting the TypeCode of a UInt64 value − TypeCode typeCode = uintValue.GetTypeCode(); Return Value The method returns TypeCode.UInt64 for all ulong variables, which represents the 64-bit unsigned integer type in the .NET type system. Using GetTypeCode() with UInt64 Values Example using System; public class Demo { ...

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

What is the difference between Task.WhenAll() and Task.WaitAll() in C#?

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

The Task.WaitAll() and Task.WhenAll() methods in C# serve different purposes when working with multiple asynchronous tasks. Task.WaitAll() blocks the current thread until all tasks complete, while Task.WhenAll() returns a new task that represents the completion of all provided tasks without blocking the calling thread. Understanding the difference between these methods is crucial for building responsive applications, especially those with user interfaces where blocking the main thread can freeze the UI. Syntax Following is the syntax for Task.WaitAll() − Task.WaitAll(task1, task2, task3); // or with timeout Task.WaitAll(new Task[] { task1, task2 }, TimeSpan.FromSeconds(30)); Following ...

Read More

Random.Next() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 4K+ Views

The Random.Next() method in C# is used to generate non-negative random integers. It provides multiple overloads to control the range of generated numbers, making it useful for various scenarios like games, simulations, and testing. Syntax The Random.Next() method has three overloads − public virtual int Next(); public virtual int Next(int maxValue); public virtual int Next(int minValue, int maxValue); Parameters maxValue − The exclusive upper bound of the random number (0 to maxValue-1). minValue − The inclusive lower bound of the random number. maxValue − The exclusive upper bound of the random number ...

Read More

Check if ListDictionary has a fixed size in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 326 Views

The ListDictionary class in C# provides the IsFixedSize property to determine whether the dictionary has a fixed size. A ListDictionary is a lightweight collection that stores key-value pairs using a singly linked list implementation, making it ideal for small collections (typically 10 or fewer items). Syntax Following is the syntax for checking if a ListDictionary has a fixed size − bool isFixed = listDictionary.IsFixedSize; Return Value The IsFixedSize property returns a bool value − true − The ListDictionary has a fixed size and cannot grow or shrink false ...

Read More
Showing 10051–10060 of 61,299 articles
Advertisements