NumberStyles 列挙体とは? わかりやすく解説

NumberStyles 列挙体

数値基本型クラスの Parse メソッド渡される数値文字列引数使用できるスタイル決定します

この列挙体には、メンバ値のビットごとの組み合わせ可能にする FlagsAttribute 属性含まれています。

名前空間: System.Globalization
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration NumberStyles
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum NumberStyles
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum class NumberStyles
/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum NumberStyles
SerializableAttribute 
FlagsAttribute 
ComVisibleAttribute(true) 
public enum NumberStyles
メンバメンバ
 メンバ説明
.NET Compact Framework によるサポートAllowCurrencySymbol数値文字列通貨記号含まれている場合は、通貨として解析しそれ以外場合数値として解析することを示します有効な通貨記号は、NumberFormatInfoCurrencySymbol プロパティによって決定します。 
.NET Compact Framework によるサポートAllowDecimalPoint数値文字列小数点使用できることを示します有効な小数点文字は、NumberFormatInfoNumberDecimalSeparator プロパティCurrencyDecimalSeparator プロパティによって決定します。 
.NET Compact Framework によるサポートAllowExponent数値文字列指数表記使用できることを示します。 
.NET Compact Framework によるサポートAllowHexSpecifier数値文字列16 進数値を表すことを示します有効な 16 進数値には、0-9数字A-F および a-f16 進数数字使用できます16 進数値には、左側ゼロ埋め込むことができます。このスタイル使用して解析する文字列に、"0x" のプリフィックス付けることはできません。 
.NET Compact Framework によるサポートAllowLeadingSign数値文字列先行する符号使用できることを示します有効な先行する符号文字は、NumberFormatInfo の PositiveSign プロパティと NegativeSign プロパティによって決定します。 
.NET Compact Framework によるサポートAllowLeadingWhite解析中に先行する空白文字無視することを示します有効な空白文字Unicode 値は、U+0009、U+000A、U+000B、U+000C、U+000D、および U+0020 です。 
.NET Compact Framework によるサポートAllowParentheses数値文字列に、その数値を囲む 1 ペアのかっこを使用できることを示します。 
.NET Compact Framework によるサポートAllowThousands数値文字列に、たとえば 1001000区切るグループ区切り文字使用できることを示します有効なグループ区切り文字は、NumberFormatInfoNumberGroupSeparator プロパティCurrencyGroupSeparator プロパティによって決定します各グループ桁数は、NumberFormatInfo の NumberGroupSizes プロパティと CurrencyGroupSizes プロパティによって決定します。 
.NET Compact Framework によるサポートAllowTrailingSign数値文字列に、後続する符号使用できることを示します有効な後続する符号文字は、NumberFormatInfoPositiveSign プロパティNegativeSign プロパティによって決定します。 
.NET Compact Framework によるサポートAllowTrailingWhite解析中に後続する空白文字無視することを示します有効な空白文字Unicode 値は、U+0009、U+000A、U+000B、U+000C、U+000D、および U+0020 です。 
.NET Compact Framework によるサポートAnyAllowHexSpecifier を除くすべてスタイル使用することを示します。これは複合数値スタイルです。 
.NET Compact Framework によるサポートCurrencyAllowExponent と AllowHexSpecifier を除くすべてスタイル使用することを示します。これは複合数値スタイルです。 
.NET Compact Framework によるサポートFloatAllowLeadingWhite、AllowTrailingWhite、AllowLeadingSign、AllowDecimalPoint、AllowExponent の各スタイル使用することを示します。これは複合数値スタイルです。 
.NET Compact Framework によるサポートHexNumberAllowLeadingWhite、AllowTrailingWhite、AllowHexSpecifier の各スタイル使用することを示します。これは複合数値スタイルです。 
.NET Compact Framework によるサポートIntegerAllowLeadingWhite、AllowTrailingWhite、AllowLeadingSign の各スタイル使用することを示します。これは複合数値スタイルです。 
.NET Compact Framework によるサポートNoneいずれのビット スタイル許可しないことを示します。 
.NET Compact Framework によるサポートNumberAllowLeadingWhite、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" は、複合数値スタイルにその行のそれぞれの数値スタイル含まれないことを示します

複合数値スタイル16 進表現を表の最後の行に示します

Any

Currency

Float

Integer

Number

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

[-] m . dddddd e+ xx

[-] m . dddddd e- xx

1 つ上のゼロ以外の数字 (m) が、区切り記号 (".") の前に付きますm前にマイナス記号 ("-") が付くことがあります変換実行する Type は、文字列数値桁数 (dddddd) および xxm最大値と最小値決定します。最低 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'.
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「NumberStyles 列挙体」の関連用語

NumberStyles 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



NumberStyles 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS