Csharp Articles

Page 180 of 196

DateTimeOffset.FromUnixTimeSeconds() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 993 Views

The DateTimeOffset.FromUnixTimeSeconds() method in C# is used to convert a Unix timestamp (expressed as seconds since January 1, 1970, 00:00:00 UTC) to a DateTimeOffset value. This method is particularly useful when working with Unix-based systems or APIs that return timestamps in Unix format. Syntax Following is the syntax − public static DateTimeOffset FromUnixTimeSeconds(long seconds); Parameters seconds: A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). This parameter accepts both positive and negative values. Return Value Returns a DateTimeOffset object ...

Read More

How to create 1-Tuple or Singleton Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 214 Views

The Tuple class in C# represents a 1-tuple or singleton tuple, which is a data structure that holds a single element. Unlike regular variables, tuples provide additional functionality and can be useful when you need to treat a single value as part of a tuple-based system. Syntax Following is the syntax for creating a 1-tuple − Tuple tupleName = new Tuple(value); Accessing the value using the Item1 property − T value = tupleName.Item1; Using 1-Tuple with Integer Values The following example demonstrates creating and using a 1-tuple with an ...

Read More

Type.GetEnumNames() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 145 Views

The Type.GetEnumNames() method in C# is used to return the names of the members of the current enumeration type as an array of strings. This method is particularly useful when you need to dynamically retrieve all the constant names defined in an enum type at runtime. Syntax Following is the syntax for the GetEnumNames() method − public virtual string[] GetEnumNames(); Return Value This method returns a string array containing the names of the enumeration constants. If the current type is not an enumeration type, it throws an ArgumentException. Using GetEnumNames() with Enum ...

Read More

Type.GetEnumUnderlyingType() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 159 Views

The Type.GetEnumUnderlyingType() method in C# returns the underlying data type of an enumeration. By default, enums are based on int, but they can also be based on other integral types like byte, short, long, etc. Syntax Following is the syntax − public virtual Type GetEnumUnderlyingType(); Return Value Returns a Type object representing the underlying type of the enumeration. Throws ArgumentException if the current type is not an enumeration. Using GetEnumUnderlyingType() with Default Enum Let us see an example that demonstrates getting the underlying type of a default enum − ...

Read More

Type.GetEnumValues() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 435 Views

The Type.GetEnumValues() method in C# returns an array containing the values of all constants in an enumeration type. This method is useful when you need to iterate through all possible values of an enum or perform operations on the entire set of enum values. Syntax Following is the syntax for the GetEnumValues() method − public virtual Array GetEnumValues(); Return Value Returns an Array that contains the values of the constants in the current enumeration type. The elements of the array are sorted by the binary values of the enumeration constants. Using GetEnumValues() ...

Read More

Decimal.ToOACurrency() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 150 Views

The Decimal.ToOACurrency() method in C# converts a decimal value to an OLE Automation Currency value, which is represented as a 64-bit signed integer. OLE Automation Currency is a fixed-point data type that stores currency values with 4 decimal places of precision, making it suitable for financial calculations where precision is critical. The method multiplies the decimal value by 10, 000 to preserve 4 decimal places in the integer representation. This format is commonly used in COM interop scenarios and legacy systems that require OLE Automation compatibility. Syntax Following is the syntax for the Decimal.ToOACurrency() method − ...

Read More

Decimal.ToSByte() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 99 Views

The Decimal.ToSByte() method in C# converts a decimal value to an equivalent 8-bit signed integer (sbyte). This method performs truncation, discarding any fractional part and returning only the integer portion of the decimal value. The sbyte data type can hold values from -128 to 127. If the decimal value is outside this range, an OverflowException will be thrown. Syntax Following is the syntax − public static sbyte ToSByte(decimal val); Parameters val − The decimal number to convert to an sbyte. Return Value Returns an sbyte value ...

Read More

Decimal.ToSingle() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 200 Views

The Decimal.ToSingle() method in C# is used to convert the value of the specified decimal to the equivalent single-precision floating-point number (float). This method is useful when you need to convert high-precision decimal values to float for mathematical operations or when interfacing with APIs that require float parameters. Syntax Following is the syntax − public static float ToSingle(decimal val); Parameters val − The decimal number to convert to a single-precision floating-point number. Return Value Returns a single-precision floating-point number (float) that is equivalent to the specified decimal value. Using Decimal.ToSingle() ...

Read More

Char.Parse(String) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 4K+ Views

The Char.Parse(String) method in C# is used to convert the value of the specified string to its equivalent Unicode character. This method is particularly useful when you need to extract a single character from a string representation. Syntax Following is the syntax − public static char Parse(string s); Parameters s − A string that contains a single character, or null. Return Value Returns a Unicode character that is equivalent to the sole character in s. Examples Example 1: Parsing a Letter Character The following ...

Read More

Char.ToLowerInvariant(Char) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 285 Views

The Char.ToLowerInvariant() method in C# is used to convert a Unicode character to its lowercase equivalent using the casing rules of the invariant culture. This method ensures consistent case conversion regardless of the current system culture, making it ideal for culture-independent operations. Syntax Following is the syntax − public static char ToLowerInvariant(char ch); Parameters ch − The Unicode character to convert to lowercase. Return Value Returns the lowercase equivalent of the specified character, or the same character if it has no lowercase equivalent or is already lowercase. ...

Read More
Showing 1791–1800 of 1,951 articles
« Prev 1 178 179 180 181 182 196 Next »
Advertisements