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
Articles on Trending Technologies
Technical articles with clear explanations and examples
What is the best data type to use for currency in C#?
The best data type to use for currency in C# is decimal. The decimal type is a 128-bit data type specifically designed for financial and monetary calculations that require high precision and accuracy. The decimal type can represent values ranging from 1.0 × 10^-28 to approximately 7.9 × 10^28 with 28-29 significant digits. To initialize a decimal variable, use the suffix m or M − decimal currency = 2.1m; Why Decimal is Best for Currency Unlike float and double data types, decimal can represent fractional numbers like 0.1 exactly without rounding errors. Float and ...
Read MoreWhat is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time in C#?
Converting seconds to a formatted time string in the format Hour:Minutes:Seconds:Milliseconds is a common requirement in C# applications. The most efficient approach is using the TimeSpan structure, which provides built-in methods for time calculations and formatting. TimeSpan Structure TimeSpan represents a time interval and provides properties like Hours, Minutes, Seconds, and Milliseconds for easy access to time components. The TimeSpan.FromSeconds() method creates a TimeSpan object from a given number of seconds. Syntax Following is the syntax for converting seconds using TimeSpan.FromSeconds() − TimeSpan timeSpan = TimeSpan.FromSeconds(totalSeconds); string formatted = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", ...
Read MoreMathF.Min() Method in C# with Examples
The MathF.Min() method in C# returns the smaller of two specified float values. This method is part of the MathF class, which provides mathematical functions optimized for single-precision floating-point numbers. Syntax Following is the syntax − public static float Min(float val1, float val2); Parameters val1 − The first float number to compare. val2 − The second float number to compare. Return Value Returns a float value representing the smaller of the two input parameters. If either value is NaN (Not a Number), the method returns ...
Read MoreSortedDictionary.Remove() Method in C#
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 MoreCheck if a SortedList is read-only in C#
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 MoreHow to call a static constructor or when static constructor is called in C#?
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 MoreHow to determine if C# .NET Core is installed?
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 MoreHow to change the Input Encoding Scheme of the C# Console?
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 MoreRandom.NextDouble() Method in C#
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 MoreConvert Decimal to the equivalent 64-bit unsigned integer in C#
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