System.IConvertible Interface

Assembly: Mscorlib.dll
Namespace: System
Summary
Defines methods that convert the value of the implementing reference or value type to a common language runtime type that has an equivalent value.
This class is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public interface IConvertible
Remarks
This interface provides methods to convert the value of an instance of an implementing type to a common language runtime type that has an equivalent value. The common language runtime types are Boolean, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime, Char, and String.

If there is no meaningful conversion to a common language runtime type, then a particular interface method implementation throws InvalidCastException. For example, if this interface is implemented on a Boolean type, the implementation of the IConvertible.ToDateTime method throws an exception because there is no meaningful DateTime equivalent to a Boolean type.

The common language runtime typically exposes the IConvertible interface through the Convert class. The common language runtime also uses the IConvertible interface internally, in , to simplify the code used to support conversions in the Convert class and basic common language runtime types.

In addition to the IConvertible interface, the .NET Framework provides classes called type converters for converting user-defined data types to other data types. For more information, see the the conceptual topic at MSDN: Generalized Type Conversion topic.

See also:
System Namespace

System.IConvertible Member List:

Public Methods
GetTypeCode Returns the TypeCode for this instance.
ToBoolean Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting information.
ToByte Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific formatting information.
ToChar Converts the value of this instance to an equivalent Unicode character using the specified culture-specific formatting information.
ToDateTime Converts the value of this instance to an equivalent DateTime using the specified culture-specific formatting information.
ToDecimal Converts the value of this instance to an equivalent Decimal number using the specified culture-specific formatting information.
ToDouble Converts the value of this instance to an equivalent double-precision floating-point number using the specified culture-specific formatting information.
ToInt16 Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific formatting information.
ToInt32 Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific formatting information.
ToInt64 Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific formatting information.
ToSByte Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific formatting information.
ToSingle Converts the value of this instance to an equivalent single-precision floating-point number using the specified culture-specific formatting information.
ToString Converts the value of this instance to an equivalent String using the specified culture-specific formatting information.
ToType Converts the value of this instance to an Object of the specified Type that has an equivalent value, using the specified culture-specific formatting information.
ToUInt16 Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific formatting information.
ToUInt32 Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific formatting information.
ToUInt64 Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific formatting information.

System.IConvertible Member Details

Method: GetTypeCode()
Summary
Returns the TypeCode for this instance.
This class is not CLS Compliant

C# Syntax:
TypeCode GetTypeCode();
Return Value:
The enumerated constant that is the TypeCode of the class or value type that implements this interface.

Return to top


Method: ToBoolean(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
bool ToBoolean(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A Boolean value equivalent to the value of this instance.

Return to top


Method: ToByte(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
byte ToByte(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 8-bit unsigned integer equivalent to the value of this instance.

Return to top


Method: ToChar(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent Unicode character using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
char ToChar(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A Unicode character equivalent to the value of this instance.

Return to top


Method: ToDateTime(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent DateTime using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
DateTime ToDateTime(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A DateTime instance equivalent to the value of this instance.

Return to top


Method: ToDecimal(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent Decimal number using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
decimal ToDecimal(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A Decimal number equivalent to the value of this instance.

Return to top


Method: ToDouble(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent double-precision floating-point number using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
double ToDouble(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A double-precision floating-point number equivalent to the value of this instance.

Return to top


Method: ToInt16(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
short ToInt16(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 16-bit signed integer equivalent to the value of this instance.

Return to top


Method: ToInt32(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
int ToInt32(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 32-bit signed integer equivalent to the value of this instance.

Return to top


Method: ToInt64(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
long ToInt64(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 64-bit signed integer equivalent to the value of this instance.

Return to top


Method: ToSByte(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
sbyte ToSByte(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 8-bit signed integer equivalent to the value of this instance.

Return to top


Method: ToSingle(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent single-precision floating-point number using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
float ToSingle(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A single-precision floating-point number equivalent to the value of this instance.

Return to top


Method: ToString(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent String using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
string ToString(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
A String instance equivalent to the value of this instance.

Return to top


Method: ToType(
   Type conversionType,
   IFormatProvider provider
)
Summary
Converts the value of this instance to an Object of the specified Type that has an equivalent value, using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
object ToType(
   Type conversionType,
   IFormatProvider provider
);
Parameters:

conversionType

The Type to which the value of this instance is converted.

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An Object instance of type conversionType whose value is equivalent to the value of this instance.

Return to top


Method: ToUInt16(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
ushort ToUInt16(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 16-bit unsigned integer equivalent to the value of this instance.

Return to top


Method: ToUInt32(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
uint ToUInt32(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 32-bit unsigned integer equivalent to the value of this instance.

Return to top


Method: ToUInt64(
   IFormatProvider provider
)
Summary
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific formatting information.
This class is not CLS Compliant

C# Syntax:
ulong ToUInt64(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider interface implementation that supplies culture-specific formatting information.

Return Value:
An 64-bit unsigned integer equivalent to the value of this instance.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.