Programming Articles

Page 46 of 2547

SortedDictionary.Remove() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 173 Views

The SortedDictionary.Remove() method in C# is used to remove the element with the specified key from the SortedDictionary. This method returns a bool value indicating whether the removal was successful. Syntax Following is the syntax for the Remove() method − public bool Remove (TKey key); Parameters key − The key of the element to remove from the SortedDictionary. Return Value The method returns true if the element is successfully found and removed; otherwise, false. This method also returns false if the key is not found in the original SortedDictionary. ...

Read More

Check if a SortedList is read-only in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 133 Views

The SortedList class in C# provides the IsReadOnly property to determine whether the collection can be modified. A read-only SortedList cannot have elements added, removed, or modified after creation. Syntax Following is the syntax to check if a SortedList is read-only − bool isReadOnly = sortedList.IsReadOnly; Return Value The IsReadOnly property returns a bool value − true if the SortedList is read-only false if the SortedList allows modifications Example The following example demonstrates how to check if a SortedList is read-only − ...

Read More

How to call a static constructor or when static constructor is called in C#?

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

A static constructor in C# is called automatically by the Common Language Runtime (CLR) before the first instance of a class is created or any static members are referenced. It is used to initialize static data or perform actions that need to be executed only once during the application's lifetime. Unlike instance constructors, static constructors cannot be called directly and have no control over when they execute − the CLR handles their invocation automatically. Syntax Following is the syntax for declaring a static constructor − static ClassName() { // initialization code } ...

Read More

How to determine if C# .NET Core is installed?

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

Determining if C# .NET Core is installed on your system is essential for development and deployment. The dotnet command-line interface (CLI) provides several built-in options to check installation status, versions, and available components. These commands will display environment information if .NET Core is installed, or throw an error if it's not found. Using dotnet --info The --info option prints detailed information about the .NET Core installation and machine environment, including the current operating system and commit SHA of the .NET Core version − dotnet --info This command provides comprehensive details about your .NET installation, ...

Read More

How to change the Input Encoding Scheme of the C# Console?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 219 Views

To change the Input Encoding Scheme of the Console in C#, use the Console.InputEncoding property. This property allows you to specify how the console interprets input characters, which is particularly useful when working with different character sets or international text. Syntax Following is the syntax for setting the console input encoding − Console.InputEncoding = Encoding.EncodingType; To retrieve the current input encoding − Encoding currentEncoding = Console.InputEncoding; Common Encoding Types Encoding Type Description Encoding.UTF8 UTF-8 encoding for Unicode characters Encoding.ASCII ASCII ...

Read More

Random.NextDouble() Method in C#

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

The Random.NextDouble() method in C# generates a random floating-point number that is greater than or equal to 0.0 and less than 1.0. This method is useful for generating decimal probabilities, percentages, or scaling random values to specific ranges. Syntax Following is the syntax for the NextDouble() method − public virtual double NextDouble(); Return Value The method returns a double value in the range [0.0, 1.0), where 0.0 is inclusive and 1.0 is exclusive. Using NextDouble() for Basic Random Numbers Example using System; public class Demo { ...

Read More

Convert Decimal to the equivalent 64-bit unsigned integer in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 649 Views

To convert the value of a Decimal to the equivalent 64-bit unsigned integer (ulong), C# provides the Decimal.ToUInt64() method. This method truncates the decimal portion and returns only the integer part as a ulong value. Syntax Following is the syntax for converting a decimal to 64-bit unsigned integer − ulong result = Decimal.ToUInt64(decimalValue); Parameters decimalValue − A Decimal number to be converted to a 64-bit unsigned integer. Return Value Returns a ulong value equivalent to the decimal value, with the fractional part truncated (not rounded). Using Decimal.ToUInt64() with ...

Read More

How can we call one constructor from another in the same class in C#?

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

In C#, you can call one constructor from another constructor within the same class using the this keyword. This technique is called constructor chaining. To call a constructor from a parent class, use the base keyword. Syntax Following is the syntax for calling another constructor in the same class using this − public ClassName(parameters) : this(arguments) { // additional initialization code } Following is the syntax for calling a parent class constructor using base − public DerivedClass(parameters) : base(arguments) { // derived class initialization code } ...

Read More

How can I limit Parallel.ForEach in C#?

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

The Parallel.ForEach loop in C# executes iterations across multiple threads for improved performance. However, sometimes you need to limit the degree of parallelism to control resource usage, avoid overwhelming external systems, or manage thread contention. This is accomplished using ParallelOptions. Syntax Following is the basic syntax for Parallel.ForEach − Parallel.ForEach(collection, item => { // process item }); Following is the syntax for limiting parallelism using ParallelOptions − Parallel.ForEach(collection, new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, item => { ...

Read More

Why singleton class is always sealed in C#?

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

A singleton class is marked as sealed in C# to prevent inheritance and maintain the single instance guarantee that is fundamental to the singleton pattern. The sealed keyword ensures that no other class can inherit from the singleton class, which could potentially create multiple instances and violate the singleton principle. Why Singleton Classes Must Be Sealed The singleton pattern ensures only one instance of a class exists throughout the application lifecycle. If a singleton class allows inheritance, derived classes could create their own instances, breaking this fundamental rule. Here are the key reasons − Prevents Multiple ...

Read More
Showing 451–460 of 25,467 articles
« Prev 1 44 45 46 47 48 2547 Next »
Advertisements