The DateTime.CompareTo() method in C# is used to compare the value of this instance to a specified DateTime value. It returns an integer indicating the chronological relationship between two DateTime objects. Syntax Following is the syntax − public int CompareTo(DateTime value); Parameters value − The DateTime object to compare with the current instance. Return Value It returns an integer value − < 0 − If this instance is earlier than the specified value 0 − If this instance is the same as the specified value > 0 − If ... Read More
The MathF.Atanh() method in C# returns the hyperbolic arc-tangent of a single-precision floating-point value. The hyperbolic arc-tangent is the inverse of the hyperbolic tangent function and is defined only for values in the range (-1, 1). For values outside this range, the method returns NaN (Not a Number). The method is useful in mathematical calculations involving hyperbolic functions and inverse transformations. Syntax Following is the syntax − public static float Atanh(float val); Parameters val − A single-precision floating-point number representing the hyperbolic tangent whose inverse is to be found. Must ... Read More
Numeric promotion in C# is the automatic conversion of smaller numeric types to larger types during arithmetic operations. This ensures that operations between different numeric types can be performed without data loss, following C#'s type promotion rules. When performing arithmetic operations, C# automatically promotes operands to a common type that can safely hold the result. For example, when multiplying a short and ushort, both are promoted to int before the operation. How Numeric Promotion Works The C# compiler follows a specific hierarchy when promoting numeric types during arithmetic operations − Numeric Promotion ... Read More
In C#, strings are immutable, meaning their characters cannot be changed directly. However, you can change characters in a string using the StringBuilder class, which provides a mutable sequence of characters. The StringBuilder class allows you to modify individual characters using indexer notation str[index] = newChar, where the index is zero-based. Syntax Following is the syntax for changing a character in a StringBuilder − StringBuilder stringBuilder = new StringBuilder("original"); stringBuilder[index] = 'newChar'; Using StringBuilder to Change Characters Let's say our string is − StringBuilder str = new StringBuilder(); str.Append("pre"); ... Read More
The DateTime.MaxValue property in C# returns the maximum possible value for a DateTime object. This represents the largest date and time that can be stored in a DateTime structure, which is December 31, 9999 at 11:59:59.9999999 PM. This property is useful when you need to initialize a DateTime variable with the highest possible value, compare dates to find the maximum, or set upper bounds in date range validations. Syntax Following is the syntax for accessing the maximum DateTime value − DateTime maxValue = DateTime.MaxValue; DateTime MaxValue Example The following example demonstrates how ... Read More
The Char.IsLetterOrDigit() method in C# determines whether a specified Unicode character is categorized as a letter or a decimal digit. This method is useful for validating input characters, parsing strings, and filtering alphanumeric content. Syntax Following is the syntax for the Char.IsLetterOrDigit() method − public static bool IsLetterOrDigit(char ch); There is also an overloaded version that works with strings − public static bool IsLetterOrDigit(string s, int index); Parameters ch − The Unicode character to evaluate. s − A string. index − The position of the character to evaluate ... Read More
Decimal to multiple-base conversion is a common programming task where we convert a decimal number to binary, octal, hexadecimal, or any other base. Using a stack data structure makes this process efficient because stacks follow the Last-In-First-Out (LIFO) principle, which naturally reverses the remainder sequence obtained during division. How It Works The conversion algorithm repeatedly divides the decimal number by the target base and stores remainders in a stack. When we pop elements from the stack, we get the digits in the correct order for the converted number. Decimal to Binary Conversion (45 ... Read More
A jagged array in C# is an array of arrays where each sub-array can have different lengths. Unlike multi-dimensional arrays, jagged arrays provide flexibility in storing varying amounts of data in each row. To find the length and rank of a jagged array, you can use the Length property, GetLowerBound() and GetUpperBound() methods, and the Rank property. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[rows][]; Following are the methods and properties to find length and rank − arrayName.Length ... Read More
The StringBuilder class in C# provides the Remove() method to delete a sequence of characters starting from a specific index position. This method is more efficient than string manipulation when performing multiple character operations. Syntax Following is the syntax for the Remove() method − StringBuilder.Remove(int startIndex, int length) Parameters startIndex − The zero-based position where removal begins. length − The number of characters to remove. Return Value The method returns a reference to the same StringBuilder instance after the removal operation, allowing for method chaining. ... Read More
The TakeLast() method in C# returns a specified number of elements from the end of a sequence. It's part of the LINQ library and provides an efficient way to extract the last few elements from arrays, lists, or other enumerable collections. Syntax Following is the syntax for using TakeLast() − IEnumerable TakeLast(int count) Parameters count − The number of elements to return from the end of the sequence. Return Value Returns an IEnumerable containing the specified number of elements from the end of the source sequence. Using TakeLast() ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance