DateTime.Subtract() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

1K+ Views

The DateTime.Subtract() method in C# is used to subtract either a DateTime or a TimeSpan from the current DateTime instance. This method has two overloads: one subtracts a DateTime and returns the time difference as a TimeSpan, while the other subtracts a TimeSpan and returns a new DateTime. Syntax Following are the two overloads of the DateTime.Subtract() method − public TimeSpan Subtract(DateTime value); public DateTime Subtract(TimeSpan value); Parameters value − Either a DateTime instance to subtract from the current date, or a TimeSpan representing the duration to subtract. ... Read More

DateTimeOffset.ToUnixTimeMilliseconds() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

873 Views

The DateTimeOffset.ToUnixTimeMilliseconds() method in C# returns the number of milliseconds that have elapsed since the Unix epoch (1970-01-01T00:00:00.000Z). This method is useful for converting .NET datetime objects to Unix timestamps, which are commonly used in web APIs, databases, and cross-platform applications. Syntax Following is the syntax − public long ToUnixTimeMilliseconds(); Return Value The method returns a long value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC. For dates before the Unix epoch, the return value will be negative. Unix Epoch Timeline ... Read More

What is compile time polymorphism in C#?

Samual Sam
Updated on 17-Mar-2026 07:04:35

2K+ Views

Compile-time polymorphism in C# is a type of polymorphism where the method to be called is determined during compilation rather than at runtime. It is also known as static polymorphism or early binding, because the method binding occurs at compile time. C# provides two main techniques to implement compile-time polymorphism − Method Overloading and Operator Overloading. The compiler resolves which method to call based on the method signature (method name, number of parameters, and parameter types). Compile-time Polymorphism Method Resolution at Compile Time Compiler determines which method ... Read More

Comparing enum members in C#

Chandu yadav
Updated on 17-Mar-2026 07:04:35

2K+ Views

To compare enum members in C#, you can use the Enum.CompareTo() method or standard comparison operators. Enum comparison is based on the underlying numeric values assigned to each enum member. Syntax Following is the syntax for using CompareTo() method − enumValue1.CompareTo(enumValue2) Following is the syntax for using comparison operators − enumValue1 == enumValue2 // equality enumValue1 > enumValue2 // greater than enumValue1 < enumValue2 // less than Return Value The CompareTo() method returns − Negative value if the first enum is ... Read More

DateTime.ToBinary() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

783 Views

The DateTime.ToBinary() method in C# is used to serialize the current DateTime object to a 64-bit binary value that can be used to recreate the DateTime object. The return value is a 64-bit signed integer that encodes both the date/time value and the DateTimeKind. Syntax Following is the syntax − public long ToBinary(); Return Value The method returns a long (64-bit signed integer) that represents the serialized DateTime. This binary value can later be used with DateTime.FromBinary() to reconstruct the original DateTime object. How It Works The binary representation encodes different ... Read More

DateTimeOffset.ToUnixTimeSeconds() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

656 Views

The DateTimeOffset.ToUnixTimeSeconds() method in C# returns the number of seconds that have elapsed since the Unix epoch (1970-01-01T00:00:00Z). This method is particularly useful when working with Unix timestamps or when interfacing with systems that use Unix time. Syntax Following is the syntax − public long ToUnixTimeSeconds(); Return Value The method returns a long value representing the number of seconds since the Unix epoch. If the DateTimeOffset represents a time before the epoch, the return value will be negative. Unix Time Calculation Unix Epoch ... Read More

What is boxing in C#?

George John
Updated on 17-Mar-2026 07:04:35

587 Views

Boxing in C# is the process of converting a value type to an object type. When boxing occurs, the value stored on the stack is copied to an object stored on the heap memory. This is an implicit conversion that allows value types to be treated as reference types. Syntax Boxing happens implicitly when a value type is assigned to an object variable − int valueType = 50; object boxedValue = valueType; // implicit boxing Unboxing requires explicit casting to convert back to the original value type − object boxedValue = 50; ... Read More

C# Program to skip elements from a sequence as long as the specified condition is true

Chandu yadav
Updated on 17-Mar-2026 07:04:35

300 Views

The SkipWhile() method in C# is a LINQ extension method that skips elements from the beginning of a sequence as long as a specified condition remains true. Once the condition becomes false, it returns all remaining elements including the first element that failed the condition. Syntax Following is the syntax for the SkipWhile() method − public static IEnumerable SkipWhile( this IEnumerable source, Func predicate ) Parameters source − The sequence of elements to skip from. predicate − A function to ... Read More

DateTime.ToFileTime() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

598 Views

The DateTime.ToFileTime() method in C# converts the value of the current DateTime object to a Windows file time. Windows file time represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (UTC). This method is particularly useful when working with file system operations, as Windows uses this format internally for file timestamps. Syntax Following is the syntax − public long ToFileTime(); Return Value The method returns a long value representing the current DateTime object as a Windows file time. How It Works The method ... Read More

Decimal.Add() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

1K+ Views

The Decimal.Add() method in C# is a static method that adds two specified decimal values and returns their sum. This method provides precise decimal arithmetic, which is essential for financial calculations where floating-point errors must be avoided. Syntax Following is the syntax − public static decimal Add(decimal val1, decimal val2); Parameters val1 − The first decimal value to add. val2 − The second decimal value to add. Return Value Returns a decimal value that represents the sum of val1 and val2. Using Decimal.Add() with Regular Values Example ... Read More

Advertisements