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
Decimal constants in C#
The decimal type in C# provides built-in constants to retrieve the minimum and maximum possible values for decimal numbers. These constants are useful for validation, range checking, and initialization purposes. Syntax Following is the syntax for declaring a decimal constant − decimal variableName = value M; Following is the syntax for accessing decimal constants − decimal.MaxValue // Maximum possible decimal value decimal.MinValue // Minimum possible decimal value Decimal Constants The decimal type provides two important constants − decimal.MaxValue − Returns the largest possible decimal ...
Read MoreC# OverflowException
The OverflowException in C# is thrown when an arithmetic operation results in a value that exceeds the range of the target data type. This commonly occurs during type conversions, arithmetic operations, or when parsing strings that contain values outside the acceptable range. Common Scenarios OverflowException is typically thrown in the following situations − Converting a string to an integer when the value exceeds int.MaxValue or int.MinValue Arithmetic operations that result in overflow (in checked context) Casting between numeric types where the source value is too large for the target type ...
Read MoreDateTime.ToLocalTime() Method in C#
The DateTime.ToLocalTime() method in C# converts a DateTime object to the local time zone of the current system. This method is particularly useful when working with UTC times or when you need to display times in the user's local time zone. Syntax Following is the syntax for the ToLocalTime() method − public DateTime ToLocalTime(); Return Value This method returns a new DateTime object that represents the local time equivalent of the current DateTime instance. If the original DateTime has Kind property set to DateTimeKind.Local, it returns the same value unchanged. How It ...
Read MoreC# Program to display priority of Thread
In C#, thread priority determines how the operating system schedules threads for execution. The Priority property of the Thread class allows you to both view and set the priority of a thread. Thread priority is represented by the ThreadPriority enumeration. Syntax To get the current thread and display its priority − Thread thread = Thread.CurrentThread; ThreadPriority priority = thread.Priority; To set a thread's priority − thread.Priority = ThreadPriority.High; ThreadPriority Enumeration Values Priority Level Description Lowest The thread has the lowest priority ...
Read MoreWhat are two-dimensional arrays in C#?
A two-dimensional array in C# is an array of arrays, where elements are arranged in rows and columns like a table or matrix. It stores data in a grid format with two indices: one for the row and one for the column. Two-dimensional arrays are useful for representing tabular data, matrices, game boards, or any data structure that requires a grid-like organization. Syntax Following is the syntax for declaring a two-dimensional array − datatype[, ] arrayName = new datatype[rows, columns]; Following is the syntax for initializing a two-dimensional array with values − ...
Read MoreC# Program to check if a number is Positive, Negative, Odd, Even, Zero
In C#, you can determine if a number is positive, negative, odd, even, or zero using simple conditional statements and arithmetic operations. This involves checking the sign of the number and using the modulus operator to determine if a number is divisible by 2. Logic for Number Classification To classify a number, we use the following approaches − Positive/Negative/Zero: Compare the number with zero using relational operators. Odd/Even: Use the modulus operator (%) to check if the remainder when divided by 2 is zero. Number Classification Logic ...
Read MoreManipulate decimals with numeric operators in C#
The decimal data type in C# provides precise arithmetic operations for financial and monetary calculations. You can manipulate decimals using standard numeric operators such as +, -, *, /, and %. Decimal literals in C# must be suffixed with M or m to distinguish them from double values. This ensures precision is maintained during calculations. Syntax Following is the syntax for declaring decimal variables − decimal variableName = value M; Following is the syntax for basic arithmetic operations with decimals − decimal result = decimal1 + decimal2; // Addition decimal ...
Read MoreC# Decimal ("D") Format Specifier
The "D" (decimal) format specifier in C# is used to format integer types as a string of decimal digits (0-9). It displays the number with optional zero-padding to achieve a specified minimum length. Syntax Following is the syntax for the "D" format specifier − number.ToString("D") // Basic decimal format number.ToString("Dn") // Decimal with minimum n digits Where n is the minimum number of digits. If the number has fewer digits, it will be padded with leading zeros. Parameters ...
Read MoreC# program to display factors of entered number
A factor of a number is any integer that divides the number evenly without leaving a remainder. For example, the factors of 12 are 1, 2, 3, 4, 6, and 12 because each of these numbers divides 12 exactly. To find factors of a number in C#, we use the modulus operator (%) to check if the remainder is zero when dividing the number by potential factors. Algorithm The algorithm to find factors involves the following steps − Start with 1 and iterate through all numbers up to the given number For each number, check ...
Read MoreWhat is the difference between a float, double and a decimal in C#?
Float, double, and decimal are all value types in C# that represent numeric data with fractional parts. Each type differs in precision, memory size, and intended use cases. Understanding these differences is crucial for choosing the appropriate type for your specific needs. Syntax Following is the syntax for declaring float, double, and decimal variables − float floatValue = 3.14f; // 'f' suffix required double doubleValue = 3.14; // default for literals decimal decimalValue = 3.14m; // 'm' suffix required Float Value Type Float ...
Read More