In This Article

ObjectExtensions Class

Provides extension methods for the object type.

public static class ObjectExtensions
Inheritance:
object object

Methods

FormatNumber<T>(T, string?, IFormatProvider?)

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

public static string FormatNumber<T>(this T number, string? format, IFormatProvider? provider = null) where T : INumber<T>
Type Parameters:
T -

The number type.

Parameter Type Description
number T

The number to be formatted.

format string

A numeric (e.g., "N2") or composite (e.g., "{0:N2}") format string.

provider IFormatProvider

An object that supplies culture-specific formatting information.

Returns

string:

The string representation of the value of this instance as specified by format and provider.

Exceptions

Type Condition
ArgumentNullException
FormatException
NotSupportedException

TryConvertToDouble(object?, out double)

Tries to convert an object to a double value, using the current thread's NumberFormat.

public static bool TryConvertToDouble(this object? value, out double doubleValue)
Parameter Type Description
value object

The value to examine.

doubleValue double

The converted double value.

Returns

bool:

true if the conversion was successful; otherwise, false.

TryConvertToDouble(object?, IFormatProvider?, out double)

Tries to convert an object to a double value, using the specified IFormatProvider.

public static bool TryConvertToDouble(this object? value, IFormatProvider? provider, out double doubleValue)
Parameter Type Description
value object

The value to examine.

provider IFormatProvider

The IFormatProvider to use, which uses the current thread's NumberFormat when null.

doubleValue double

The converted double value.

Returns

bool:

true if the conversion was successful; otherwise, false.

Inherited Members