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
Programming Articles
Page 85 of 2547
Comparing enum members in C#
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 MoreDateTime.ToBinary() Method in C#
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 MoreDateTimeOffset.ToUnixTimeSeconds() Method in C#
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 MoreWhat is boxing in C#?
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 MoreC# Program to skip elements from a sequence as long as the specified condition is true
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 MoreDateTime.ToFileTime() Method in C#
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 MoreDecimal.Add() Method in C#
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 MoreWhat is composition in C#?
Composition in C# is a design principle where one class contains an instance of another class as a private member, creating a "has-a" relationship. In composition, the contained object (child) cannot exist independently of the container object (parent). When the parent object is destroyed, the child object is also destroyed, establishing a strong ownership relationship. Composition represents a part-of relationship, which is a special type of association that implies strong coupling between objects. Syntax Following is the basic syntax for implementing composition in C# − public class ContainedClass { // properties and ...
Read MoreImplicit conversion from 64-bit signed integer (long) to Decimal in C#
The long type represents a 64-bit signed integer in C#. C# allows implicit conversion from long to decimal because no data loss occurs during this conversion. The decimal type can accommodate all possible long values while providing higher precision. Syntax Following is the syntax for implicit conversion from long to decimal − long longValue = 123456789; decimal decimalValue = longValue; // Implicit conversion How It Works The conversion happens automatically because the decimal type has a wider range and higher precision than long. The decimal type can represent all integer values that ...
Read MoreDecimal.Ceiling() Method in C#
The Decimal.Ceiling() method in C# returns the smallest integral value that is greater than or equal to the specified decimal number. This method rounds up to the nearest whole number, regardless of whether the decimal portion is less than or greater than 0.5. Syntax Following is the syntax − public static decimal Ceiling(decimal val); Parameters val − A decimal number that needs to be rounded up to the nearest integer. Return Value Returns a decimal value representing the smallest integer greater than or equal to the input value. ...
Read More