指定したスタイルの数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。
UInt16 型は CLS との互換性がありません。CLS との互換性が必要な場合は、代わりに Int32 を使用してください。Int16 は、元の値が UInt16.MaxValue の半分以下の場合に使用されます。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
<CLSCompliant(False)>
Overloads Public Shared Function Parse( _ ByVal s As String, _ ByVal style As NumberStyles _) As UInt16
[C#]
[CLSCompliant(false)]
public static ushort Parse(strings,NumberStylesstyle);
[C++]
[CLSCompliant(false)]
public: static unsigned short Parse(String* s,NumberStylesstyle);
[JScript]
public
CLSCompliant(false)
static function Parse(s : String,style : NumberStyles) : UInt16;
パラメータ
- s
変換する数値を表す文字列。 - style
s の許容形式を示す、1 つ以上の NumberStyles 定数の組み合わせ。
戻り値
s で指定した数値と等しい 16 ビット符号なし整数。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | s が null 参照 (Visual Basic では Nothing) です。 |
ArgumentException | style が、 NumberStyles 列挙体からのビット フラグの有効な組み合わせではありません。 |
FormatException | s の書式が、 style に準拠した書式ではありません。 |
OverflowException | s が MinValue 未満の数値か、 MaxValue より大きい数値を表しています。 |
解説
s パラメータには、次の書式の数値を指定します。
[ws][sign]digits[ws]
角かっこ ('[' および ']') で囲まれている項目は省略可能です。その他の項目は次のとおりです。
- ws
省略可能な空白。 - sign
省略可能な正の符号。 - digits
0 から 9 までの一連の数字。
style パラメータには、ビットごとの OR 演算を使用して、1 つ以上の NumberStyles 列挙定数を組み合わせて指定できます。 Any および AllowDecimalPoint は、このメソッドから返される型として無効であるため除きます。
使用例
[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, NumberStyles styles) {
Temperature temp = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2), styles);
}
else {
temp.Value = UInt16.Parse(s, styles);
}
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, NumberStyles styles) {
Temperature* temp = new Temperature();
if( s->TrimEnd(NULL)->EndsWith("'F") ) {
temp->Value = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2), styles);
}
else {
if( s->TrimEnd(NULL)->EndsWith("'C") ) {
temp->Celsius = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2), styles);
}
else {
temp->Value = UInt16::Parse(s, styles);
}
}
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, styles : NumberStyles) : Temperature {
var temp : Temperature = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2), styles);
}
else {
temp.Value = UInt16.Parse(s, styles);
}
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