数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。
UInt16 型は CLS との互換性がありません。CLS との互換性が必要な場合は、代わりに Int32 を使用してください。Int16 は、元の値が UInt16.MaxValue の半分以下の場合に使用されます。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
<CLSCompliant(False)>
Overloads Public Shared Function Parse( _ ByVal s As String _) As UInt16
[C#]
[CLSCompliant(false)]
public static ushort Parse(strings);
[C++]
[CLSCompliant(false)]
public: static unsigned short Parse(String* s);
[JScript]
public
CLSCompliant(false)
static function Parse(s : String) : UInt16;
パラメータ
- s
変換する数値を表す文字列。
戻り値
s に格納されている数値と等しい 16 ビット符号なし整数。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | s が null 参照 (Visual Basic では Nothing) です。 |
FormatException | s の書式が正しくありません。 |
OverflowException | s が MinValue 未満の数値か、 MaxValue より大きい数値を表しています。 |
解説
s パラメータには、次の書式の数値を指定します。
[ws][sign]digits[ws]
角かっこ ('[' および ']') で囲まれている項目は省略可能です。その他の項目は次のとおりです。
- ws
省略可能な空白。 - sign
省略可能な正の符号。 - digits
0 から 9 までの一連の数字。
s パラメータは、現在のシステム カルチャに対して初期化された NumberFormatInfo 内の書式情報を使用して解析されます。詳細については、 NumberFormatInfo.CurrentInfo のトピックを参照してください。
使用例
[C#, C++, JScript] Parse メソッドの例を次に示します。
public class Temperature {
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
public static Temperature Parse(string s) {
Temperature temp = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2) );
}
else {
temp.Value = UInt16.Parse(s);
}
return temp;
}
// The value holder
protected ushort m_value;
public ushort Value {
get {
return m_value;
}
set {
m_value = value;
}
}
}
[C++]
public __gc class Temperature {
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
// The value holder
protected:
short m_value;
public:
static Temperature* Parse(String* s) {
Temperature* temp = new Temperature();
if( s->TrimEnd(NULL)->EndsWith("'F") ) {
temp->Value = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2) );
}
else {
if( s->TrimEnd(NULL)->EndsWith("'C") ) {
temp->Celsius = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2) );
}
else {
temp->Value = UInt16::Parse(s);
}
}
return temp;
};
__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 {
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
public static function Parse(s : String) : Temperature {
var temp : Temperature = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2) );
}
else {
temp.Value = UInt16.Parse(s);
}
return temp;
}
// 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.Parse オーバーロードの一覧 | 書式設定の概要 | ToString