次の方法で共有


UInt64.Parse メソッド

定義

数値の文字列形式を等価の 64 ビット符号なし整数に変換します。

オーバーロード

Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、等価の 64 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String, IFormatProvider)

指定したカルチャ固有の形式の数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Char>, IFormatProvider)

文字のスパンを値に解析します。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String)

数値の文字列形式を等価の 64 ビット符号なし整数に変換します。

Parse(String, NumberStyles)

指定したスタイルの数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

Parse(String, NumberStyles, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Decimal.Parse(String)

指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

public:
 static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
 static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::UInt64>::Parse;
[System.CLSCompliant(false)]
public static ulong Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static ulong Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static ulong Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint64
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As ULong

パラメーター

s
String

変換する数値を表す文字列。 文字列は、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

sで指定された数値に相当する 64 ビット符号なし整数。

実装

属性

例外

s パラメーターは nullです。

styleNumberStyles 値ではありません。

-又は-

style は、AllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s パラメーターは、styleに準拠した形式ではありません。

パラメーターは、UInt64.MinValue より小さいか、UInt64.MaxValueより大きい数値を表します。

-又は-

s には、0 以外の小数部の数字が含まれます。

次の例では、Parse(String, NumberStyles, IFormatProvider) メソッドを使用して、数値のさまざまな文字列形式を 64 ビット符号なし整数値に変換します。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] cultureNames= { "en-US", "fr-FR" };
      NumberStyles[] styles= { NumberStyles.Integer,
                               NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
      string[] values = { "170209", "+170209.0", "+170209,0", "-103214.00",
                                 "-103214,00", "104561.1", "104561,1" };
      
      // Parse strings using each culture
      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         Console.WriteLine("Parsing strings using the {0} culture", 
                           ci.DisplayName);
         // Use each style.
         foreach (NumberStyles style in styles)
         {
            Console.WriteLine("   Style: {0}", style.ToString());
            // Parse each numeric string.
            foreach (string value in values)
            {
               try {
                  Console.WriteLine("      Converted '{0}' to {1}.", value,
                                    UInt64.Parse(value, style, ci));
               }
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);
               }      
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt64 type.",
                                    value);
               }
            }
         }
      }                                    
   }
}
// The example displays the following output:
//       Style: Integer
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Unable to parse '+170209,0'.
//          Unable to parse '-103214.00'.
//          Unable to parse '-103214,00'.
//          Unable to parse '104561.1'.
//          Unable to parse '104561,1'.
//       Style: Integer, AllowDecimalPoint
//          Converted '170209' to 170209.
//          Converted '+170209.0' to 170209.
//          Unable to parse '+170209,0'.
//          '-103214.00' is out of range of the UInt64 type.
//          Unable to parse '-103214,00'.
//          '104561.1' is out of range of the UInt64 type.
//          Unable to parse '104561,1'.
//    Parsing strings using the French (France) culture
//       Style: Integer
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Unable to parse '+170209,0'.
//          Unable to parse '-103214.00'.
//          Unable to parse '-103214,00'.
//          Unable to parse '104561.1'.
//          Unable to parse '104561,1'.
//       Style: Integer, AllowDecimalPoint
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Converted '+170209,0' to 170209.
//          Unable to parse '-103214.00'.
//          '-103214,00' is out of range of the UInt64 type.
//          Unable to parse '104561.1'.
//          '104561,1' is out of range of the UInt64 type.
open System
open System.Globalization

let cultureNames = [| "en-US"; "fr-FR" |]
let styles = [| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |]
let values = 
    [| "170209"; "+170209.0"; "+170209,0"; "-103214.00"
       "-103214,00"; "104561.1"; "104561,1" |]

// Parse strings using each culture
for cultureName in cultureNames do
    let ci = CultureInfo cultureName
    printfn $"Parsing strings using the {ci.DisplayName} culture"
    // Use each style.
    for style in styles do
        printfn $"   Style: {style}"
        // Parse each numeric string.
        for value in values do
            try
                printfn $"      Converted '{value}' to {UInt64.Parse(value, style, ci)}."
            with
            | :? FormatException ->
                printfn $"      Unable to parse '{value}'."
            | :? OverflowException ->
                printfn $"      '{value}' is out of range of the UInt64 type."
// The example displays the following output:
//       Style: Integer
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Unable to parse '+170209,0'.
//          Unable to parse '-103214.00'.
//          Unable to parse '-103214,00'.
//          Unable to parse '104561.1'.
//          Unable to parse '104561,1'.
//       Style: Integer, AllowDecimalPoint
//          Converted '170209' to 170209.
//          Converted '+170209.0' to 170209.
//          Unable to parse '+170209,0'.
//          '-103214.00' is out of range of the UInt64 type.
//          Unable to parse '-103214,00'.
//          '104561.1' is out of range of the UInt64 type.
//          Unable to parse '104561,1'.
//    Parsing strings using the French (France) culture
//       Style: Integer
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Unable to parse '+170209,0'.
//          Unable to parse '-103214.00'.
//          Unable to parse '-103214,00'.
//          Unable to parse '104561.1'.
//          Unable to parse '104561,1'.
//       Style: Integer, AllowDecimalPoint
//          Converted '170209' to 170209.
//          Unable to parse '+170209.0'.
//          Converted '+170209,0' to 170209.
//          Unable to parse '-103214.00'.
//          '-103214,00' is out of range of the UInt64 type.
//          Unable to parse '104561.1'.
//          '104561,1' is out of range of the UInt64 type.
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim cultureNames() As String = { "en-US", "fr-FR" }
      Dim styles() As NumberStyles = { NumberStyles.Integer, _
                                       NumberStyles.Integer Or NumberStyles.AllowDecimalPoint }
      Dim values() As String = { "170209", "+170209.0", "+170209,0", "-103214.00", _
                                 "-103214,00", "104561.1", "104561,1" }
      
      ' Parse strings using each culture
      For Each cultureName As String In cultureNames
         Dim ci As New CultureInfo(cultureName)
         Console.WriteLine("Parsing strings using the {0} culture", ci.DisplayName)
         ' Use each style.
         For Each style As NumberStyles In styles
            Console.WriteLine("   Style: {0}", style.ToString())
            ' Parse each numeric string.
            For Each value As String In values
               Try
                  Console.WriteLine("      Converted '{0}' to {1}.", value, _
                                    UInt64.Parse(value, style, ci))
               Catch e As FormatException
                  Console.WriteLine("      Unable to parse '{0}'.", value)   
               Catch e As OverflowException
                  Console.WriteLine("      '{0}' is out of range of the UInt64 type.", _
                                    value)         
               End Try
            Next
         Next
      Next                                    
   End Sub
End Module
' The example displays the following output:
'       Style: Integer
'          Converted '170209' to 170209.
'          Unable to parse '+170209.0'.
'          Unable to parse '+170209,0'.
'          Unable to parse '-103214.00'.
'          Unable to parse '-103214,00'.
'          Unable to parse '104561.1'.
'          Unable to parse '104561,1'.
'       Style: Integer, AllowDecimalPoint
'          Converted '170209' to 170209.
'          Converted '+170209.0' to 170209.
'          Unable to parse '+170209,0'.
'          '-103214.00' is out of range of the UInt64 type.
'          Unable to parse '-103214,00'.
'          '104561.1' is out of range of the UInt64 type.
'          Unable to parse '104561,1'.
'    Parsing strings using the French (France) culture
'       Style: Integer
'          Converted '170209' to 170209.
'          Unable to parse '+170209.0'.
'          Unable to parse '+170209,0'.
'          Unable to parse '-103214.00'.
'          Unable to parse '-103214,00'.
'          Unable to parse '104561.1'.
'          Unable to parse '104561,1'.
'       Style: Integer, AllowDecimalPoint
'          Converted '170209' to 170209.
'          Unable to parse '+170209.0'.
'          Converted '+170209,0' to 170209.
'          Unable to parse '-103214.00'.
'          '-103214,00' is out of range of the UInt64 type.
'          Unable to parse '104561.1'.
'          '104561,1' is out of range of the UInt64 type.

注釈

style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白、正符号または負符号記号など) を定義します。 NumberStyles 列挙型のビット フラグの組み合わせである必要があります。

styleの値によっては、s パラメーターに次の要素が含まれる場合があります。

[ ws][][符号][.fractional_digits][E[符号]exponential_digits][ws]

角かっこ ([ と ]) の要素は省略可能です。 style NumberStyles.AllowHexSpecifierが含まれている場合、s パラメーターには次の要素が含まれる場合があります。

[ws]hexdigits[ws]

次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。 NumberStyles.AllowLeadingWhite フラグが含まれている style 場合は、s の先頭に空白が表示され、styleNumberStyles.AllowTrailingWhite フラグが含まれている場合は、s の末尾に空白を表示できます。
$ カルチャ固有の通貨記号。 文字列内での位置は、provider パラメーターの GetFormat メソッドによって返される NumberFormatInfo オブジェクトの CurrencyPositivePattern プロパティによって定義されます。 styleNumberStyles.AllowCurrencySymbol フラグが含まれている場合、通貨記号は s に表示されます。
sign 省略可能な記号。 (s に負の符号が含まれており、0 以外の数値を表す場合、メソッドは OverflowException をスローします)。NumberStyles.AllowLeadingSign フラグ style 含まれている場合は s の先頭に表示され、NumberStyles.AllowTrailingSign フラグ style 含まれている場合は s の末尾に表示されます。 s でかっこを使用すると、styleNumberStyles.AllowParentheses フラグが含まれている場合に負の値を示すことができます。
桁の 0 から 9 までの数字のシーケンス。
. カルチャ固有の小数点記号。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、現在のカルチャの小数点記号は s に表示されます。
fractional_digits styleNumberStyles.AllowExponent フラグを含む場合は数字 0 から 9 が 1 回以上出現し、含まれていない場合は 1 つ以上の数字 0 が出現します。 小数部の数字は、NumberStyles.AllowDecimalPoint フラグ style 含まれている場合にのみ、s に表示できます。
E "e" または "E" 文字。値が指数 (指数) 表記で表されることを示します。 s パラメーターは、NumberStyles.AllowExponent フラグが含まれている場合 style 指数表記で数値を表すことができます。
exponential_digits 0 から 9 までの数字のシーケンス。 s パラメーターは、NumberStyles.AllowExponent フラグが含まれている場合 style 指数表記で数値を表すことができます。
hexdigits を する 0 から f、または 0 から F までの 16 進数のシーケンス。

手記

s で終了する NUL (U+0000) 文字は、style 引数の値に関係なく、解析操作では無視されます。

10 進数のみを含む文字列 (NumberStyles.None スタイルに対応) は、常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、この入力文字列に存在する可能性がありますが、存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、sに存在する可能性がある要素に与える影響を示しています。

非複合 NumberStyles 数字に加えて s で許可される要素
NumberStyles.None 10 進数のみ。
NumberStyles.AllowDecimalPoint 小数点 (.) および fractional_digits 要素。 ただし、スタイルに NumberStyles.AllowExponent フラグが含まれていない場合、fractional_digits は 1 桁以上の 0 桁のみで構成する必要があります。それ以外の場合は、OverflowException がスローされます。
NumberStyles.AllowExponent 指数表記を示す "e" または "E" 文字と、exponential_digits
NumberStyles.AllowLeadingWhite sの先頭にある ws 要素。
NumberStyles.AllowTrailingWhite sの末尾にある ws 要素。
NumberStyles.AllowLeadingSign 数字の前の記号。
NumberStyles.AllowTrailingSign 数字の後の記号。
NumberStyles.AllowParentheses 負の値を示すために の前と後のかっこ。
NumberStyles.AllowThousands グループ区切り記号 (,) 要素。
NumberStyles.AllowCurrencySymbol currency ($) 要素。

NumberStyles.AllowHexSpecifier フラグを使用する場合、s は 16 進値である必要があります。 有効な 16 進文字は、0 から 9、A から F、および a から f です。 "0x" などのプレフィックスはサポートされていないため、解析操作が失敗します。 組み合わせることができる他のフラグは、NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteだけです。 (NumberStyles 列挙には、両方の空白フラグを含む複合数値スタイル (NumberStyles.HexNumber) が含まれています)。

手記

s パラメーターが 16 進数の文字列表現である場合、その前に 16 進数として区別する装飾 (0x&hなど) を付けることはできません。 これにより、解析操作で例外がスローされます。

provider パラメーターは、GetFormat メソッドが sの形式に関するカルチャ固有の情報を提供する NumberFormatInfo オブジェクトを返す IFormatProvider 実装です。 provider パラメーターを使用して、解析操作にカスタム書式情報を指定するには、次の 3 つの方法があります。

  • 書式設定情報を提供する実際の NumberFormatInfo オブジェクトを渡すことができます。 (GetFormat の実装は単にそれ自体を返します)。

  • 書式設定を使用するカルチャを指定する CultureInfo オブジェクトを渡すことができます。 その NumberFormat プロパティは、書式設定情報を提供します。

  • カスタムの IFormatProvider 実装を渡すことができます。 その GetFormat メソッドは、書式設定情報を提供する NumberFormatInfo オブジェクトをインスタンス化して返す必要があります。

providernullされている場合は、現在のカルチャの NumberFormatInfo オブジェクトが使用されます。

こちらもご覧ください

  • ToString
  • .NET での数値文字列の解析の

適用対象

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

重要

この API は CLS 準拠ではありません。

指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、等価の 64 ビット符号なし整数に変換します。

public static ulong Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
[System.CLSCompliant(false)]
public static ulong Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
[System.CLSCompliant(false)]
public static ulong Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint64
[<System.CLSCompliant(false)>]
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As ULong

パラメーター

s
ReadOnlySpan<Char>

変換する数値を表す文字を含むスパン。 スパンは、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

sで指定された数値に相当する 64 ビット符号なし整数。

実装

属性

適用対象

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs

UTF-8 文字のスパンを値に解析します。

public static ulong Parse (ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As ULong

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

style
NumberStyles

utf8Textに存在できる数値スタイルのビットごとの組み合わせ。

provider
IFormatProvider

utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

utf8Text解析の結果。

実装

適用対象

Parse(String, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Decimal.Parse(String)

指定したカルチャ固有の形式の数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

public:
 static System::UInt64 Parse(System::String ^ s, IFormatProvider ^ provider);
public:
 static System::UInt64 Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<System::UInt64>::Parse;
[System.CLSCompliant(false)]
public static ulong Parse (string s, IFormatProvider provider);
public static ulong Parse (string s, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static ulong Parse (string s, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * IFormatProvider -> uint64
static member Parse : string * IFormatProvider -> uint64
Public Shared Function Parse (s As String, provider As IFormatProvider) As ULong

パラメーター

s
String

変換する数値を表す文字列。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

sで指定された数値に相当する 64 ビット符号なし整数。

実装

属性

例外

s パラメーターは nullです。

s パラメーターが正しいスタイルではありません。

パラメーターは、UInt64.MinValue より小さいか、UInt64.MaxValueより大きい数値を表します。

次の例は、Web フォームのボタン クリック イベント ハンドラーです。 HttpRequest.UserLanguages プロパティによって返される配列を使用して、ユーザーのロケールを決定します。 その後、そのロケールに対応する CultureInfo オブジェクトをインスタンス化します。 その CultureInfo オブジェクトに属する NumberFormatInfo オブジェクトが Parse(String, IFormatProvider) メソッドに渡され、ユーザーの入力が UInt64 値に変換されます。

protected void OkToSingle_Click(object sender, EventArgs e)
{
    string locale;
    float number;
    CultureInfo culture;

    // Return if string is empty
    if (String.IsNullOrEmpty(this.inputNumber.Text))
        return;

    // Get locale of web request to determine possible format of number
    if (Request.UserLanguages.Length == 0)
        return;
    locale = Request.UserLanguages[0];
    if (String.IsNullOrEmpty(locale))
        return;

    // Instantiate CultureInfo object for the user's locale
    culture = new CultureInfo(locale);

    // Convert user input from a string to a number
    try
    {
        number = Single.Parse(this.inputNumber.Text, culture.NumberFormat);
    }
    catch (FormatException)
    {
        return;
    }
    catch (Exception)
    {
        return;
    }
    // Output number to label on web form
    this.outputNumber.Text = "Number is " + number.ToString();
}
Protected Sub OkToSingle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkToSingle.Click
   Dim locale As String
   Dim culture As CultureInfo
   Dim number As Single

   ' Return if string is empty
   If String.IsNullOrEmpty(Me.inputNumber.Text) Then Exit Sub

   ' Get locale of web request to determine possible format of number
   If Request.UserLanguages.Length = 0 Then Exit Sub
   locale = Request.UserLanguages(0)
   If String.IsNullOrEmpty(locale) Then Exit Sub

   ' Instantiate CultureInfo object for the user's locale
   culture = New CultureInfo(locale)

   ' Convert user input from a string to a number
   Try
      number = Single.Parse(Me.inputNumber.Text, culture.NumberFormat)
   Catch ex As FormatException
      Exit Sub
   Catch ex As OverflowException
      Exit Sub
   End Try

   ' Output number to label on web form
   Me.outputNumber.Text = "Number is " & number.ToString()
End Sub

注釈

Parse(String, IFormatProvider) メソッドのこのオーバーロードは、通常、さまざまな方法で書式設定できるテキストを UInt64 値に変換するために使用されます。 たとえば、ユーザーが入力したテキストを HTML テキスト ボックスに数値に変換するために使用できます。

s パラメーターには、次の形式が含まれています。

[ws][sign]digits[ws]

角かっこ ([ と ]) の項目は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。
sign 省略可能な正符号。値 0 を表 s 場合は負符号。
桁の 0 から 9 までの数字のシーケンス。

s パラメーターは、NumberStyles.Integer スタイルを使用して解釈されます。 符号なし整数値の 10 進数に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 (負の符号が存在する場合、s は 0 の値を表す必要があります。または、メソッドは OverflowExceptionをスローします)。sに存在できるカルチャ固有の書式設定情報と共にスタイル要素を明示的に定義するには、Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。

provider パラメーターは、GetFormat メソッドが sの形式に関するカルチャ固有の情報を提供する NumberFormatInfo オブジェクトを返す IFormatProvider 実装です。 provider パラメーターを使用して、解析操作にカスタム書式情報を指定するには、次の 3 つの方法があります。

  • 書式設定情報を提供する実際の NumberFormatInfo オブジェクトを渡すことができます。 (GetFormat の実装は単にそれ自体を返します)。

  • 書式設定を使用するカルチャを指定する CultureInfo オブジェクトを渡すことができます。 その NumberFormat プロパティは、書式設定情報を提供します。

  • カスタムの IFormatProvider 実装を渡すことができます。 その GetFormat メソッドは、書式設定情報を提供する NumberFormatInfo オブジェクトをインスタンス化して返す必要があります。

providernullされている場合は、現在のカルチャの NumberFormatInfo が使用されます。

こちらもご覧ください

適用対象

Parse(ReadOnlySpan<Char>, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

文字のスパンを値に解析します。

public:
 static System::UInt64 Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::UInt64>::Parse;
public static ulong Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> uint64
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As ULong

パラメーター

s
ReadOnlySpan<Char>

解析する文字のスパン。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

s解析の結果。

実装

適用対象

Parse(ReadOnlySpan<Byte>, IFormatProvider)

ソース:
UInt64.cs
ソース:
UInt64.cs

UTF-8 文字のスパンを値に解析します。

public:
 static System::UInt64 Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::UInt64>::Parse;
public static ulong Parse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> uint64
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As ULong

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

provider
IFormatProvider

utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

utf8Text解析の結果。

実装

適用対象

Parse(String)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Decimal.Parse(String)

数値の文字列形式を等価の 64 ビット符号なし整数に変換します。

public:
 static System::UInt64 Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static ulong Parse (string s);
public static ulong Parse (string s);
[<System.CLSCompliant(false)>]
static member Parse : string -> uint64
static member Parse : string -> uint64
Public Shared Function Parse (s As String) As ULong

パラメーター

s
String

変換する数値を表す文字列。

戻り値

sに含まれる数値に相当する 64 ビット符号なし整数。

属性

例外

s パラメーターは nullです。

s パラメーターの形式が正しくありません。

パラメーターは、UInt64.MinValue より小さいか、UInt64.MaxValueより大きい数値を表します。

次の例では、Parse メソッドを使用して文字列値の配列を解析します。

string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
                    "0xFA1B", "163042", "-10", "14065839182",
                    "16e07", "134985.0", "-12034" };
foreach (string value in values)
{
   try {
      ulong number = UInt64.Parse(value); 
      Console.WriteLine("{0} --> {1}", value, number);
   }
   catch (FormatException) {
      Console.WriteLine("{0}: Bad Format", value);
   }   
   catch (OverflowException) {
      Console.WriteLine("{0}: Overflow", value);   
   }  
}
// The example displays the following output:
//       +13230 --> 13230
//       -0 --> 0
//       1,390,146: Bad Format
//       $190,235,421,127: Bad Format
//       0xFA1B: Bad Format
//       163042 --> 163042
//       -10: Overflow
//       14065839182 --> 14065839182
//       16e07: Bad Format
//       134985.0: Bad Format
//       -12034: Overflow
let values = 
    [| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
       "0xFA1B"; "163042"; "-10"; "14065839182"
       "16e07"; "134985.0"; "-12034" |]
for value in values do
    try 
        let number = UInt64.Parse value 
        printfn $"{value} --> {number}"
    with
    | :? FormatException ->
        printfn $"{value}: Bad Format"
    | :? OverflowException ->
        printfn $"{value}: Overflow"
// The example displays the following output:
//       +13230 --> 13230
//       -0 --> 0
//       1,390,146: Bad Format
//       $190,235,421,127: Bad Format
//       0xFA1B: Bad Format
//       163042 --> 163042
//       -10: Overflow
//       14065839182 --> 14065839182
//       16e07: Bad Format
//       134985.0: Bad Format
//       -12034: Overflow
Dim values() As String = { "+13230", "-0", "1,390,146", "$190,235,421,127", _
                           "0xFA1B", "163042", "-10", "14065839182", _
                           "16e07", "134985.0", "-12034" }
For Each value As String In values
   Try
      Dim number As ULong = UInt64.Parse(value) 
      Console.WriteLine("{0} --> {1}", value, number)
   Catch e As FormatException
      Console.WriteLine("{0}: Bad Format", value)
   Catch e As OverflowException
      Console.WriteLine("{0}: Overflow", value)   
   End Try  
Next
' The example displays the following output:
'       +13230 --> 13230
'       -0 --> 0
'       1,390,146: Bad Format
'       $190,235,421,127: Bad Format
'       0xFA1B: Bad Format
'       163042 --> 163042
'       -10: Overflow
'       14065839182 --> 14065839182
'       16e07: Bad Format
'       134985.0: Bad Format
'       -12034: Overflow

注釈

s パラメーターは、次の形式の数値の文字列形式である必要があります。

[ ws][符号][ws]

角かっこ ([ と ]) の要素は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。
sign 省略可能な記号。 有効な符号文字は、現在のカルチャの NumberFormatInfo.NegativeSign プロパティと NumberFormatInfo.PositiveSign プロパティによって決まります。 ただし、負符号記号は 0 でのみ使用できます。それ以外の場合、メソッドは OverflowExceptionをスローします。
桁の 0 から 9 までの数字のシーケンス。 先行ゼロは無視されます。

手記

s パラメーターで指定された文字列は、NumberStyles.Integer スタイルを使用して解釈されます。 グループ区切り記号または小数点区切り記号を含めることはできません。また、小数部を含めることはできません。

s パラメーターは、現在のシステム カルチャ用に初期化された System.Globalization.NumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 詳細については、NumberFormatInfo.CurrentInfoを参照してください。 特定のカルチャの書式設定情報を使用して文字列を解析するには、Parse(String, IFormatProvider) メソッドを使用します。

こちらもご覧ください

  • ToString
  • .NET での数値文字列の解析の

適用対象

Parse(String, NumberStyles)

ソース:
UInt64.cs
ソース:
UInt64.cs
ソース:
UInt64.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Decimal.Parse(String)

指定したスタイルの数値の文字列形式を、等価の 64 ビット符号なし整数に変換します。

public:
 static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static ulong Parse (string s, System.Globalization.NumberStyles style);
public static ulong Parse (string s, System.Globalization.NumberStyles style);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles -> uint64
static member Parse : string * System.Globalization.NumberStyles -> uint64
Public Shared Function Parse (s As String, style As NumberStyles) As ULong

パラメーター

s
String

変換する数値を表す文字列。 文字列は、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

sの許可される形式を指定する列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

戻り値

sで指定された数値に相当する 64 ビット符号なし整数。

属性

例外

s パラメーターは nullです。

styleNumberStyles 値ではありません。

-又は-

style は、AllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s パラメーターは、styleに準拠した形式ではありません。

パラメーターは、UInt64.MinValue より小さいか、UInt64.MaxValueより大きい数値を表します。

-又は-

s には、0 以外の小数部の数字が含まれます。

次の例では、複数の NumberStyles 値を使用して、文字列配列内の各要素を解析しようとします。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values= { " 214309 ", "1,064,181", "(0)", "10241+", " + 21499 ", 
                         " +21499 ", "122153.00", "1e03ff", "91300.0e-2" };
      NumberStyles whitespace =  NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
      NumberStyles[] styles= { NumberStyles.None, whitespace, 
                               NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | whitespace, 
                               NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, 
                               NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint };

      // Attempt to convert each number using each style combination.
      foreach (string value in values)
      {
         Console.WriteLine("Attempting to convert '{0}':", value);
         foreach (NumberStyles style in styles)
         {
            try {
               ulong number = UInt64.Parse(value, style);
               Console.WriteLine("   {0}: {1}", style, number);
            }   
            catch (FormatException) {
               Console.WriteLine("   {0}: Bad Format", style);
            }   
            catch (OverflowException)
            {
               Console.WriteLine("   {0}: Overflow", value);         
            }         
         }
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//    Attempting to convert ' 214309 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214309
//       Integer, AllowTrailingSign: 214309
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064,181':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064181
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '(0)':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '10241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 10241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 21499
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '122153.00':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 122153
//    
//    Attempting to convert '1e03ff':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '91300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 913
open System
open System.Globalization

let values =
    [| " 214309 "; "1,064,181"; "(0)"; "10241+"; " + 21499 " 
       " +21499 "; "122153.00"; "1e03ff"; "91300.0e-2" |]
let whitespace =  NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite
let styles =
    [| NumberStyles.None; whitespace 
       NumberStyles.AllowLeadingSign ||| NumberStyles.AllowTrailingSign ||| whitespace 
       NumberStyles.AllowThousands ||| NumberStyles.AllowCurrencySymbol 
       NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint |]

// Attempt to convert each number using each style combination.
for value in values do
    printfn $"Attempting to convert '{value}':"
    for style in styles do
        try
            let number = UInt64.Parse(value, style)
            printfn $"   {style}: {number}"
        with
        | :? FormatException ->
            printfn $"   {style}: Bad Format"
        | :? OverflowException ->
            printfn $"   {value}: Overflow"
    printfn ""
// The example displays the following output:
//    Attempting to convert ' 214309 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214309
//       Integer, AllowTrailingSign: 214309
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064,181':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064181
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '(0)':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '10241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 10241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 21499
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '122153.00':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 122153
//    
//    Attempting to convert '1e03ff':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '91300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 913
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { " 214309 ", "1,064,181", "(0)", "10241+", _
                                 " + 21499 ", " +21499 ", "122153.00", _
                                 "1e03ff", "91300.0e-2" }
      Dim whitespace As NumberStyles =  NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite
      Dim styles() As NumberStyles = { NumberStyles.None, _
                                       whitespace, _
                                       NumberStyles.AllowLeadingSign Or NumberStyles.AllowTrailingSign Or whitespace, _
                                       NumberStyles.AllowThousands Or NumberStyles.AllowCurrencySymbol, _
                                       NumberStyles.AllowExponent Or NumberStyles.AllowDecimalPoint }

      ' Attempt to convert each number using each style combination.
      For Each value As String In values
         Console.WriteLine("Attempting to convert '{0}':", value)
         For Each style As NumberStyles In styles
            Try
               Dim number As ULong = UInt64.Parse(value, style)
               Console.WriteLine("   {0}: {1}", style, number)
            Catch e As FormatException
               Console.WriteLine("   {0}: Bad Format", style)
            Catch e As OverflowException
               Console.WriteLine("   {0}: Overflow", value)         
            End Try         
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    Attempting to convert ' 214309 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: 214309
'       Integer, AllowTrailingSign: 214309
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '1,064,181':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: 1064181
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '(0)':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '10241+':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 10241
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' + 21499 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' +21499 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 21499
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '122153.00':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 122153
'    
'    Attempting to convert '1e03ff':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '91300.0e-2':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 913

注釈

style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白、正符号または負符号記号、グループ区切り記号、小数点記号など) を定義します。 style は、NumberStyles 列挙型のビット フラグの組み合わせである必要があります。 style パラメーターを使用すると、s に 16 進数の文字列形式が含まれている場合、s で表される数値システム (10 進数または 16 進数) が実行時にのみ認識される場合、または sで空白または記号記号を禁止する場合に、このメソッドのオーバーロードが役立ちます。

styleの値によっては、s パラメーターに次の要素が含まれる場合があります。

[ ws][][sign][,][fractional_digits][E[符号]exponential_digits][ws]

角かっこ ([ と ]) の要素は省略可能です。 styleNumberStyles.AllowHexSpecifierが含まれている場合、s パラメーターには次の要素が含まれる場合があります。

[ws]hexdigits[ws]

次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。 styleNumberStyles.AllowLeadingWhite フラグが含まれている場合は、s の開始時に空白が表示され、styleNumberStyles.AllowTrailingWhite フラグが含まれている場合は、s の末尾に空白を表示できます。
$ カルチャ固有の通貨記号。 文字列内での位置は、現在のカルチャの NumberFormatInfo.CurrencyNegativePattern プロパティと NumberFormatInfo.CurrencyPositivePattern プロパティによって定義されます。 styleNumberStyles.AllowCurrencySymbol フラグが含まれている場合、現在のカルチャの通貨記号は s に表示されます。
sign 省略可能な記号。 styleNumberStyles.AllowLeadingSign フラグが含まれている場合は s の開始時に表示され、styleNumberStyles.AllowTrailingSign フラグが含まれている場合は s の末尾に表示されます。 s でかっこを使用すると、styleNumberStyles.AllowParentheses フラグが含まれている場合に負の値を示すことができます。 ただし、負符号記号は 0 でのみ使用できます。それ以外の場合、メソッドは OverflowExceptionをスローします。
桁の

fractional_digits

exponential_digits
0 から 9 までの数字のシーケンス。 fractional_digitsの場合、数字 0 のみが有効です。
カルチャ固有のグループ区切り記号。 styleNumberStyles.AllowThousands フラグが含まれている場合、現在のカルチャのグループ区切り記号を s に表示できます。
. カルチャ固有の小数点記号。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、現在のカルチャの小数点記号は s に表示されます。 解析操作が成功するには、数字 0 のみを小数桁として表示できます。fractional_digits 他の数字が含まれている場合は、FormatException がスローされます。
E "e" または "E" 文字。値が指数 (指数) 表記で表されることを示します。 s パラメーターは、NumberStyles.AllowExponent フラグが含まれている場合 style 指数表記で数値を表すことができます。
hexdigits を する 0 から f、または 0 から F までの 16 進数のシーケンス。

手記

s で終了する NUL (U+0000) 文字は、style 引数の値に関係なく、解析操作では無視されます。

数字のみを含む文字列 (NumberStyles.None スタイルに対応) は、UInt64 型の範囲内にある場合、常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、入力文字列内に存在する可能性がありますが、存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、sに存在する可能性がある要素に与える影響を示しています。

NumberStyles 数字に加えて s で許可される要素
None 要素のみ。
AllowDecimalPoint 小数点 (.) と 小数部の桁数 要素。
AllowExponent 指数表記を示す "e" または "E" 文字と、exponential_digits
AllowLeadingWhite sの先頭にある ws 要素。
AllowTrailingWhite sの末尾にある ws 要素。
AllowLeadingSign sの先頭にある 記号 要素です。
AllowTrailingSign の末尾にある要素 記号。
AllowParentheses 符号、数値を囲むかっこの形式で要素に署名します。
AllowThousands グループ区切り記号 (,) 要素。
AllowCurrencySymbol currency ($) 要素。
Currency すべての要素。 ただし、s は、指数表記で 16 進数または数値を表すことはできません。
Float の先頭または末尾の ws 要素、の先頭 符号、および小数点 (.) 記号。 s パラメーターでは指数表記を使用することもできます。
Number wssign、グループ区切り記号 ()、および小数点 (.) 要素。
Any すべての要素。 ただし、s は 16 進数を表すことはできません。

他の NumberStyles 値とは異なり、sに特定のスタイル要素が存在する場合、NumberStyles.AllowHexSpecifier スタイル値は、s の個々の数値が常に 16 進数として解釈されることを意味します。 有効な 16 進文字は、0 から 9、A から F、および a から f です。 "0x" などのプレフィックスはサポートされていないため、解析操作が失敗します。 style パラメーターと組み合わせることができる他のフラグは、NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteだけです。 (NumberStyles 列挙には、両方の空白フラグを含む複合数値スタイル (NumberStyles.HexNumber) が含まれています)。

手記

s が 16 進数の文字列表現である場合、16 進数として区別する装飾 (0x&hなど) を前に付けることはできません。 これにより、変換が失敗します。

s パラメーターは、現在のシステム カルチャ用に初期化された NumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 解析操作に書式設定情報を使用するカルチャを指定するには、Parse(String, NumberStyles, IFormatProvider) オーバーロードを呼び出します。

こちらもご覧ください

適用対象