NumberStyles 列挙体
この列挙体には、メンバ値のビットごとの組み合わせを可能にする FlagsAttribute 属性が含まれています。
名前空間: System.Globalizationアセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <FlagsAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration NumberStyles

メンバ名 | 説明 | |
---|---|---|
![]() | AllowCurrencySymbol | 数値文字列に通貨記号が含まれている場合は、通貨として解析し、それ以外の場合は数値として解析することを示します。有効な通貨記号は、NumberFormatInfo の CurrencySymbol プロパティによって決定します。 |
![]() | AllowDecimalPoint | 数値文字列に小数点を使用できることを示します。有効な小数点の文字は、NumberFormatInfo の NumberDecimalSeparator プロパティと CurrencyDecimalSeparator プロパティによって決定します。 |
![]() | AllowExponent | 数値文字列に指数表記を使用できることを示します。 |
![]() | AllowHexSpecifier | 数値文字列が 16 進数値を表すことを示します。有効な 16 進数値には、0-9 の数字と A-F および a-f の 16 進数の数字を使用できます。16 進数値には、左側にゼロを埋め込むことができます。このスタイルを使用して解析する文字列に、"0x" のプリフィックスを付けることはできません。 |
![]() | AllowLeadingSign | 数値文字列に先行する符号を使用できることを示します。有効な先行する符号の文字は、NumberFormatInfo の PositiveSign プロパティと NegativeSign プロパティによって決定します。 |
![]() | AllowLeadingWhite | 解析中に先行する空白文字を無視することを示します。有効な空白文字の Unicode 値は、U+0009、U+000A、U+000B、U+000C、U+000D、および U+0020 です。 |
![]() | AllowParentheses | 数値文字列に、その数値を囲む 1 ペアのかっこを使用できることを示します。 |
![]() | AllowThousands | 数値文字列に、たとえば 100 の桁と 1000 の桁を区切るグループ区切り文字を使用できることを示します。有効なグループ区切り文字は、NumberFormatInfo の NumberGroupSeparator プロパティと CurrencyGroupSeparator プロパティによって決定します。各グループの桁数は、NumberFormatInfo の NumberGroupSizes プロパティと CurrencyGroupSizes プロパティによって決定します。 |
![]() | AllowTrailingSign | 数値文字列に、後続する符号を使用できることを示します。有効な後続する符号の文字は、NumberFormatInfo の PositiveSign プロパティと NegativeSign プロパティによって決定します。 |
![]() | AllowTrailingWhite | 解析中に後続する空白文字を無視することを示します。有効な空白文字の Unicode 値は、U+0009、U+000A、U+000B、U+000C、U+000D、および U+0020 です。 |
![]() | Any | AllowHexSpecifier を除くすべてのスタイルを使用することを示します。これは複合数値スタイルです。 |
![]() | Currency | AllowExponent と AllowHexSpecifier を除くすべてのスタイルを使用することを示します。これは複合数値スタイルです。 |
![]() | Float | AllowLeadingWhite、AllowTrailingWhite、AllowLeadingSign、AllowDecimalPoint、AllowExponent の各スタイルを使用することを示します。これは複合数値スタイルです。 |
![]() | HexNumber | AllowLeadingWhite、AllowTrailingWhite、AllowHexSpecifier の各スタイルを使用することを示します。これは複合数値スタイルです。 |
![]() | Integer | AllowLeadingWhite、AllowTrailingWhite、AllowLeadingSign の各スタイルを使用することを示します。これは複合数値スタイルです。 |
![]() | None | いずれのビット スタイルも許可しないことを示します。 |
![]() | Number | AllowLeadingWhite、AllowTrailingWhite、AllowLeadingSign、AllowTrailingSign、AllowDecimalPoint、および AllowThousands の各スタイルを使用することを示します。これは複合数値スタイルです。 |

通貨記号、桁区切り記号、小数点記号、および先行する符号に使用する記号は、NumberFormatInfo で指定します。
AllowCurrencySymbol 値と AllowDecimalPoint 値は、Parse メソッドが数値型のインスタンスを通貨または数値のいずれとして処理するかを判断します。したがって、これは関連付けられた NumberFormatInfo の通貨プロパティまたは数値プロパティのいずれを使用するかを判断します。たとえば、AllowCurrencySymbol を指定した場合、Parse メソッドは CurrencyDecimalSeparator および CurrencyGroupSeparator などの通貨プロパティを使用します。これに対して、AllowDecimalPoint を指定した場合、このメソッドは NumberDecimalSeparator および NumberGroupSeparator などの数値プロパティを使用します。
NumberStyles の属性は、フィールド フラグのビットごとの包括的 OR を使用して設定します。最上位ビット (MSB: Most Significant Bit) とは、一番左のビットです。
次の表で、行はそれぞれのフィールド フラグの数値スタイル、列はそれぞれのフィールド フラグを組み合わせた複合数値スタイルを示します。
複合数値スタイルで、"1" は複合数値スタイルにその行のそれぞれの数値スタイルが含まれることを示します。"0" は、複合数値スタイルにその行のそれぞれの数値スタイルが含まれないことを示します。
| Any | HexNumber | ||||
---|---|---|---|---|---|---|
AllowHexSpecifier (0x0200) | 0 | 0 | 0 | 0 | 0 | 1 |
AllowCurrencySymbol (0x0100) | 1 | 1 | 0 | 0 | 0 | 0 |
AllowExponent (0x0080) | 1 | 0 | 1 | 0 | 0 | 0 |
AllowThousands (0x0040) | 1 | 1 | 0 | 0 | 1 | 0 |
AllowDecimalPoint (0x0020) | 1 | 1 | 1 | 0 | 1 | 0 |
AllowParentheses (0x0010) | 1 | 1 | 0 | 0 | 0 | 0 |
AllowTrailingSign (0x0008) | 1 | 1 | 0 | 0 | 1 | 0 |
AllowLeadingSign (0x0004) | 1 | 1 | 1 | 1 | 1 | 0 |
AllowTrailingWhite (0x0002) | 1 | 1 | 1 | 1 | 1 | 1 |
AllowLeadingWhite (0x0001) | 1 | 1 | 1 | 1 | 1 | 1 |
| (0x1ff) | (0x17f) | (0x0a7) | (0x007) | (0x06f) | (0x203) |
AllowExponent スタイルは、次のいずれかの形式の数値文字列で使用します。
[-] m . dddddd E- xx
[-] m . dddddd e- xx
1 つ以上のゼロ以外の数字 (m) が、桁区切り記号 (".") の前に付きます。m の前にマイナス記号 ("-") が付くことがあります。変換を実行する Type は、文字列の数値の桁数 (dddddd) および xx と m の最大値と最小値を決定します。最低 1 つの数字の前に、プラス記号またはマイナス記号のいずれかで構成される指数部 (+ / - xx) が付きます。

次の例では、さまざまな NumberStyles フラグを使用して、文字列の解析による 32 ビット整数への変換を行う方法を示します。
using System; using System.Text; using System.Globalization; public sealed class App { static void Main() { // Parse the string as a hex value and display the value as a decimal. String num = "A"; int val = int.Parse(num, NumberStyles.HexNumber); Console.WriteLine("{0} in hex = {1} in decimal.", num, val); // Parse the string, allowing a leading sign, and ignoring leading and trailing white spaces. num = " -45 "; val = int.Parse(num, NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite); Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val); // Parse the string, allowing parentheses, and ignoring leading and trailing white spaces. num = " (37) "; val = int.Parse(num, NumberStyles.AllowParentheses | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite); Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val); } } // This code produces the following output. // // A in hex = 10 in decimal. // ' -45 ' parsed to an int is '-45'. // ' (37) ' parsed to an int is '-37'.
using namespace System; using namespace System::Text; using namespace System::Globalization; int main() { // Parse the string as a hex value and display the // value as a decimal. String^ numberString = "A"; int stringValue = Int32::Parse(numberString, NumberStyles::HexNumber); Console::WriteLine("{0} in hex = {1} in decimal.", numberString, stringValue); // Parse the string, allowing a leading sign, and ignoring // leading and trailing white spaces. numberString = " -45 "; stringValue =Int32::Parse(numberString, NumberStyles::AllowLeadingSign | NumberStyles::AllowLeadingWhite | NumberStyles::AllowTrailingWhite); Console::WriteLine("'{0}' parsed to an int is '{1}'." , numberString, stringValue); // Parse the string, allowing parentheses, and ignoring // leading and trailing white spaces. numberString = " (37) "; stringValue = Int32::Parse(numberString, NumberStyles::AllowParentheses | NumberStyles::AllowLeadingSign | NumberStyles::AllowLeadingWhite | NumberStyles::AllowTrailingWhite); Console::WriteLine("'{0}' parsed to an int is '{1}'." , numberString, stringValue); } // This code produces the following output. // // A in hex = 10 in decimal. // ' -45 ' parsed to an int is '-45'. // ' (37) ' parsed to an int is '-37'.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- NumberStyles 列挙体のページへのリンク