数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。
UInt16 型は CLS との互換性がありません。CLS との互換性が必要な場合は、代わりに Int32 を使用してください。Int16 は、元の値が UInt16.MaxValue の半分以下の場合に使用されます。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
オーバーロードの一覧
数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function Parse(String) As UInt16
指定したカルチャ固有の書式による数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。このメソッドは、CLS と互換性がありません。
[Visual Basic] Overloads Public Shared Function Parse(String, IFormatProvider) As UInt16
[C++] public: static unsigned short Parse(String*, IFormatProvider*);
[JScript] public static function Parse(String, IFormatProvider) : UInt16;
指定したスタイルの数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function Parse(String, NumberStyles) As UInt16
[C++] public: static unsigned short Parse(String*, NumberStyles);
[JScript] public static function Parse(String, NumberStyles) : UInt16;
指定したスタイルおよびカルチャ固有の書式による数値の文字列形式を、それと等価な 16 ビット符号なし整数に変換します。このメソッドは、CLS と互換性がありません。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function Parse(String, NumberStyles, IFormatProvider) As UInt16
[C#] public static ushort Parse(string, NumberStyles, IFormatProvider);
[C++] public: static unsigned short Parse(String*, NumberStyles, IFormatProvider*);
[JScript] public static function Parse(String, NumberStyles, IFormatProvider) : UInt16;
使用例
[C#, C++, JScript] Parse メソッドの例を次に示します。
[C#, C++, JScript] メモ ここでは、Parse のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
/// <summary>
/// Temperature class stores the value as UInt16
/// and delegates most of the functionality
/// to the UInt16 implementation.
/// </summary>
public class Temperature : IComparable, IFormattable {
/// <summary>
/// IComparable.CompareTo implementation.
/// </summary>
public int CompareTo(object obj) {
if(obj is Temperature) {
Temperature temp = (Temperature) obj;
return m_value.CompareTo(temp.m_value);
}
throw new ArgumentException("object is not a Temperature");
}
/// <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);
}
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
public static Temperature Parse(string s, NumberStyles styles, IFormatProvider provider) {
Temperature temp = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
}
else {
temp.Value = UInt16.Parse(s, styles, provider);
}
return temp;
}
// The value holder
protected ushort m_value;
public ushort Value {
get {
return m_value;
}
set {
m_value = value;
}
}
}
[C++]
/// <summary>
/// Temperature class stores the value as UInt16
/// and delegates most of the functionality
/// to the UInt16 implementation.
/// </summary>
public __gc class Temperature : public IComparable, public IFormattable
{
/// <summary>
/// IComparable.CompareTo implementation.
/// </summary>
protected:
short m_value;
public:
Int32 CompareTo(Object* obj) {
if(obj->GetType() == __typeof(Temperature)) {
Temperature* temp = dynamic_cast<Temperature*>(obj);
return m_value.CompareTo(__box(temp->m_value));
}
throw new ArgumentException("object is not a Temperature");
};
/// <summary>
/// IFormattable.ToString implementation.
/// </summary>
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);
};
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
static Temperature* Parse(String* s, NumberStyles styles, IFormatProvider* provider) {
Temperature* temp = new Temperature();
if( s->EndsWith("F") ) {
temp->Value = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2), styles, provider);
}
else {
if( s->EndsWith("C") ) {
temp->Celsius = UInt16::Parse( s->Remove(s->LastIndexOf('\''), 2), styles, provider);
}
else {
temp->Value = UInt16::Parse(s, styles, provider);
}
}
return temp;
};
// The value holder
__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);
};
__property static short get_MinValue(){
return UInt16::MinValue;
};
__property static short get_MaxValue() {
return UInt16::MaxValue;
};
};
[JScript]
/// <summary>
/// Temperature class stores the value as UInt16
/// and delegates most of the functionality
/// to the UInt16 implementation.
/// </summary>
public class Temperature implements IComparable, IFormattable {
/// <summary>
/// IComparable.CompareTo implementation.
/// </summary>
public function CompareTo(obj) : int {
if(obj.GetType() ==Temperature) {
var temp : Temperature = Temperature(obj);
return m_value.CompareTo(temp.m_value);
}
throw new ArgumentException("object is not a Temperature");
}
/// <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);
}
/// <summary>
/// Parses the temperature from a string in form
/// [ws][sign]digits['F|'C][ws]
/// </summary>
public static function Parse(s : String, styles : NumberStyles, provider : IFormatProvider) : Temperature {
var temp : Temperature = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = UInt16.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
}
else {
temp.Value = UInt16.Parse(s, styles, provider);
}
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 のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。