このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。
UInt16 型は CLS との互換性がありません。CLS との互換性が必要な場合は、代わりに Int32 を使用してください。Int16 は、元の値が UInt16.MaxValue の半分以下の場合に使用されます。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
Overloads Public Overridable Function ToString( _
ByVal format As String, _ ByVal provider As IFormatProvider _) As String
[C#]
public virtual string ToString(stringformat,IFormatProviderprovider);
[C++]
public: virtual String* ToString(String* format,IFormatProvider* provider);
[JScript]
public function ToString(
format : String,provider : IFormatProvider) : String;
パラメータ
- format
書式指定。 - provider
このインスタンスに関するカルチャ固有の書式情報を提供する IFormatProvider 。
戻り値
format および provider で指定された、このインスタンスの値の文字列形式。
例外
例外の種類 | 条件 |
---|---|
FormatException | format が無効です。 |
解説
format が null 参照 (Visual Basic では Nothing) または空の文字列 ("") の場合、戻り値の書式は一般書式指定子 ("G") を使用して設定されます。
provider パラメータは、 NumberFormatInfo を取得する IFormatProvider インスタンスです。 NumberFormatInfo は、このインスタンスに関するカルチャ固有の書式情報を提供します。 provider が null 参照 (Nothing) の場合、戻り値は現在のカルチャの NumberFormatInfo を使用して書式設定されます。
使用例
[C#, C++, JScript] ToString メソッドの例を次に示します。
public class Temperature : IFormattable {
/// <summary>
/// IFormattable.ToString implementation.
/// </summary>
public string ToString(string format, IFormatProvider provider) {
if( format != null && format.Equals("F") ) {
return String.Format("{0}'F", this.Value.ToString());
}
return m_value.ToString(format, provider);
}
// The value holder
protected ushort m_value;
public ushort Value {
get {
return m_value;
}
set {
m_value = value;
}
}
}
[C++]
public __gc class Temperature : public IFormattable {
/// <summary>
/// IFormattable.ToString implementation.
/// </summary>
// The value holder
protected:
short m_value;
public:
String* ToString(String* format, IFormatProvider* provider) {
if( format != NULL ) {
if( format->Equals("F") ) {
return String::Format("{0}'F", this->Value.ToString());
}
if( format->Equals("C") ) {
return String::Format("{0}'C", this->Celsius.ToString());
}
}
return m_value.ToString(format, provider);
};
__property short get_Value() {
return m_value;
};
__property void set_Value( short value) {
m_value = value;
};
__property short get_Celsius() {
return (short)((m_value-32)/2);
};
__property void set_Celsius( short value) {
m_value = (short)(value*2+32);
};
};
[JScript]
public class Temperature implements IFormattable {
/// <summary>
/// IFormattable.ToString implementation.
/// </summary>
public function ToString(format : String, provider : IFormatProvider) : String {
if( format != null && format.Equals("F") ) {
return String.Format("{0}'F", m_value.ToString());
}
return m_value.ToString(format, provider);
}
// The value holder
protected var m_value : ushort;
public function get Value() : ushort {
return m_value;
}
public function set Value(value : ushort) {
m_value = value;
}
}
[Visual Basic] Visual Basic のサンプルはありません。C#、C++、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
UInt16 構造体 | UInt16 メンバ | System 名前空間 | UInt16.ToString オーバーロードの一覧 | 書式設定の概要 | 数値書式指定文字列 | Parse | String