UInt16.Parse Yöntem

Tanım

Bir sayının dize gösterimini 16 bitlik işaretsiz tamsayı eşdeğerine dönüştürür.

Aşırı Yüklemeler

Parse(String, NumberStyles, IFormatProvider)

Belirtilen stilde ve kültüre özgü biçimdeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Bir sayının belirtilen stil ve kültüre özgü biçimdeki span gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.

Parse(String, IFormatProvider)

Belirtilen kültüre özgü biçimdeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

Parse(String, NumberStyles)

Belirtilen stildeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

Bu yöntem CLS uyumlu değildir. CLS uyumlu alternatifi şeklindedir Parse(String, NumberStyles).

Parse(ReadOnlySpan<Char>, IFormatProvider)

Bir karakter aralığını bir değere ayrıştırıyor.

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.

Parse(String)

Bir sayının dize gösterimini 16 bitlik işaretsiz tamsayı eşdeğerine dönüştürür.

Parse(String, NumberStyles, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Önemli

Bu API, CLS uyumlu değildir.

CLS uyumlu alternatif
System.Int32.Parse(String)

Belirtilen stilde ve kültüre özgü biçimdeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

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

Parametreler

s
String

Dönüştürülecek sayıyı temsil eden bir dize. Dize, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.

style
NumberStyles

içinde bulunabilecek sstil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.

provider
IFormatProvider

hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

içinde sbelirtilen sayıya eşdeğer bir 16 bit işaretsiz tamsayı.

Uygulamalar

Öznitelikler

Özel durumlar

s, null değeridir.

style bir NumberStyles değer değildir.

-veya-

styleve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.

s ile styleuyumlu bir biçimde değil.

sUInt16.MinValue değerinden küçük veya UInt16.MaxValue değerinden büyük bir sayıyı temsil eder.

-veya-

s sıfır olmayan kesirli basamaklar içerir.

Örnekler

Aşağıdaki örnek, sayıların Parse(String, NumberStyles, IFormatProvider) çeşitli dize gösterimlerini 16 bit işaretsiz tamsayı değerlerine dönüştürmek için yöntemini kullanır.

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 = { "1702", "+1702.0", "+1702,0", "-1032.00",
                          "-1032,00", "1045.1", "1045,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, 
                                    UInt16.Parse(value, style, ci));
               }                                    
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);   
               }
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt16 type.", 
                                    value);
               }
            }
         }
      }   
   }
}
// The example displays the following output:
//       Parsing strings using the English (United States) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Converted '+1702.0' to 1702.
//             Unable to parse '+1702,0'.
//             '-1032.00' is out of range of the UInt16 type.
//             Unable to parse '-1032,00'.
//             '1045.1' is out of range of the UInt16 type.
//             Unable to parse '1045,1'.
//       Parsing strings using the French (France) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Converted '+1702,0' to 1702.
//             Unable to parse '-1032.00'.
//             '-1032,00' is out of range of the UInt16 type.
//             Unable to parse '1045.1'.
//             '1045,1' is out of range of the UInt16 type.
open System
open System.Globalization

let cultureNames = [| "en-US"; "fr-FR" |]
let styles = 
    [| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |]
let values =
    [| "1702"; "+1702.0"; "+1702,0"; "-1032.00"; "-1032,00"; "1045.1"; "1045,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 {UInt16.Parse(value, style, ci)}."
            with
            | :? FormatException ->
                printfn $"      Unable to parse '{value}'."
            | :? OverflowException ->
                printfn $"      '{value}' is out of range of the UInt16 type."
// The example displays the following output:
//       Parsing strings using the English (United States) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Converted '+1702.0' to 1702.
//             Unable to parse '+1702,0'.
//             '-1032.00' is out of range of the UInt16 type.
//             Unable to parse '-1032,00'.
//             '1045.1' is out of range of the UInt16 type.
//             Unable to parse '1045,1'.
//       Parsing strings using the French (France) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Converted '+1702,0' to 1702.
//             Unable to parse '-1032.00'.
//             '-1032,00' is out of range of the UInt16 type.
//             Unable to parse '1045.1'.
//             '1045,1' is out of range of the UInt16 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 = { "1702", "+1702.0", "+1702,0", "-1032.00", _
                                 "-1032,00", "1045.1", "1045,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, _
                                    UInt16.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 UInt16 type.", _
                                    value)         
               End Try
            Next
         Next
      Next                                    
   End Sub
End Module
' The example displays the following output:
'       Parsing strings using the English (United States) culture
'          Style: Integer
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Unable to parse '+1702,0'.
'             Unable to parse '-1032.00'.
'             Unable to parse '-1032,00'.
'             Unable to parse '1045.1'.
'             Unable to parse '1045,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '1702' to 1702.
'             Converted '+1702.0' to 1702.
'             Unable to parse '+1702,0'.
'             '-1032.00' is out of range of the UInt16 type.
'             Unable to parse '-1032,00'.
'             '1045.1' is out of range of the UInt16 type.
'             Unable to parse '1045,1'.
'       Parsing strings using the French (France) culture
'          Style: Integer
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Unable to parse '+1702,0'.
'             Unable to parse '-1032.00'.
'             Unable to parse '-1032,00'.
'             Unable to parse '1045.1'.
'             Unable to parse '1045,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Converted '+1702,0' to 1702.
'             Unable to parse '-1032.00'.
'             '-1032,00' is out of range of the UInt16 type.
'             Unable to parse '1045.1'.
'             '1045,1' is out of range of the UInt16 type.

Açıklamalar

parametresi, style ayrıştırma işleminin başarılı olması için parametrede s izin verilen stil öğelerini (boşluk veya pozitif veya negatif işaret simgesi gibi) tanımlar. Sabit listesindeki bit bayraklarının NumberStyles bir bileşimi olmalıdır.

değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:

[ws] [$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]

Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. içeriyorsa styleNumberStyles.AllowHexSpecifiers, parametresi aşağıdaki öğeleri içerebilir:

[ws] hexdigits[ws]

Aşağıdaki tablo her öğeyi açıklar.

Öğe Açıklama
Ws İsteğe bağlı beyaz boşluk. Bayrağı içeriyorsa boşluk başında sstyle ve bayrağı içeriyorsa sonunda sstyleNumberStyles.AllowTrailingWhite görüntülenebilir.NumberStyles.AllowLeadingWhite
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, parametresinin yöntemi provider tarafından CurrencyPositivePattern döndürülen nesnenin özelliği NumberFormatInfo tarafından GetFormat tanımlanır. Bayrağı içeriyorsa NumberStyles.AllowCurrencySymbol para birimi simgesi içinde sstyle görünebilir.
sign İsteğe bağlı bir işaret. (yöntemi negatif bir işaret içeriyorsa bir OverflowExceptions oluşturur ve sıfır olmayan bir sayıyı temsil eder.) işareti bayrağını içeriyorsa başında sstyle ve bayrağını içeriyorsa NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign sonunu sstyle görüntüleyebilir. Parantezler, bayrağı içeriyorsa NumberStyles.AllowParentheses negatif bir değeri style belirtmek için içinde kullanılabilirs.
Basamak 0 İle 9 arasında bir basamak dizisi.
. Bir kültüre özgü ondalık nokta sembolü. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowDecimalPoint ondalık noktası simgesi içinde sstyle görünebilir.
fractional_digits Bayrağı içeriyorsa NumberStyles.AllowExponent 0-9 style basamaklarının bir veya daha fazla tekrarı veya yoksa 0 rakamının bir veya daha fazla tekrarı. Kesirli basamaklar yalnızca style bayrağı içeriyorsa NumberStyles.AllowDecimalPoint içinde görüntülenebilirs.
E Değerin üslü (bilimsel) gösterimle temsil edildiğini gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa bir sayıyı üstel gösteriminde styleNumberStyles.AllowExponent gösterebilir.
exponential_digits 0 İle 9 arasında bir basamak dizisi. parametresi, s bayrağını içeriyorsa bir sayıyı üstel gösteriminde styleNumberStyles.AllowExponent gösterebilir.
hexdigits 0 İle f veya 0 ile f arasında onaltılık basamak dizisi.

Not

içindeki s sonlandırıcı NUL (U+0000) karakterleri, bağımsız değişkenin değerinden style bağımsız olarak ayrıştırma işlemi tarafından yoksayılır.

Yalnızca ondalık basamağı olan bir dize (stile NumberStyles.None karşılık gelir) her zaman başarıyla ayrıştırılıyor. Kalan NumberStyles üyelerin çoğu, bu giriş dizesinde mevcut olabilecek ancak mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tabloda, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediği gösterilir.

Bileşik NumberStyles olmayan değerler Basamaklara ek olarak izin verilen s öğeler
NumberStyles.None Yalnızca ondalık basamaklar.
NumberStyles.AllowDecimalPoint Ondalık ayırıcı (.) ve fractional_digits öğeleri. Ancak, stil bayrağı içermiyorsa NumberStyles.AllowExponent, fractional_digits yalnızca bir veya daha fazla 0 basamak içermelidir; aksi takdirde, bir OverflowException oluşturulur.
NumberStyles.AllowExponent Exponential_digits ile birlikte üstel gösterimi gösteren "e" veya "E" karakteri.
NumberStyles.AllowLeadingWhite başındaki sws öğesi.
NumberStyles.AllowTrailingWhite sonundaki sws öğesi.
NumberStyles.AllowLeadingSign Rakamlardan önceki bir işaret.
NumberStyles.AllowTrailingSign Basamakların ardından gelen bir işaret.
NumberStyles.AllowParentheses Negatif bir değeri belirtmek için basamaklardan önce ve sonra ayraçlar.
NumberStyles.AllowThousands Grup ayırıcısı (,) öğesi.
NumberStyles.AllowCurrencySymbol Para birimi ($) öğesi.

NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s onaltılık bir değer olmalıdır. Geçerli onaltılık basamaklar 0- 9, a - f ve A - F arasındadır. "0x" gibi bir ön ek desteklenmez ve ayrıştırma işleminin başarısız olmasına neden olur. ile NumberStyles.AllowHexSpecifier birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStylesNumberStyles.HexNumberher iki boşluk bayrağını da içeren bileşik bir sayı stili içerir.)

Not

s Parametre onaltılık bir sayının dize gösterimiyse, önünde onaltılık sayı olarak ayırt eden herhangi bir süsleme (veya &hgibi0x) olamaz. Bu, ayrıştırma işleminin bir özel durum oluşturmasına neden olur.

provider parametresi, yöntemi biçimi hakkında kültüre özgü bilgiler sağlayan bir nesnesi döndüren bir IFormatProviderNumberFormatInfo uygulamadır GetFormats. Ayrıştırma işlemine provider özel biçimlendirme bilgileri sağlamak için parametresini kullanmanın üç yolu vardır:

  • Biçimlendirme bilgileri sağlayan gerçek NumberFormatInfo nesneyi geçirebilirsiniz. (Uygulaması GetFormat basitçe kendini döndürür.)

  • Biçimlendirmesi kullanılacak kültürü belirten bir CultureInfo nesne geçirebilirsiniz. Özelliği NumberFormat biçimlendirme bilgileri sağlar.

  • Özel IFormatProvider bir uygulama geçirebilirsiniz. GetFormat Yöntemi, biçimlendirme bilgileri sağlayan nesneyi örneklemeli ve döndürmelidirNumberFormatInfo.

ise providernull, NumberFormatInfo geçerli kültürün nesnesi kullanılır.

Ayrıca bkz.

Şunlara uygulanır

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Önemli

Bu API, CLS uyumlu değildir.

Bir sayının belirtilen stil ve kültüre özgü biçimdeki span gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

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

Parametreler

s
ReadOnlySpan<Char>

Dönüştürülecek sayıyı temsil eden karakterleri içeren bir yayılma alanı. Span, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.

style
NumberStyles

içinde bulunabilecek sstil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.

provider
IFormatProvider

hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

içinde sbelirtilen sayıya eşdeğer bir 16 bit işaretsiz tamsayı.

Uygulamalar

Öznitelikler

Şunlara uygulanır

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs

UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.

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

Parametreler

utf8Text
ReadOnlySpan<Byte>

Ayrıştırılacak UTF-8 karakter aralığı.

style
NumberStyles

içinde utf8Textbulunabilecek sayı stillerinin bit düzeyinde birleşimi.

provider
IFormatProvider

hakkında utf8Textkültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

ayrıştırma utf8Textsonucu.

Uygulamalar

Şunlara uygulanır

Parse(String, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Önemli

Bu API, CLS uyumlu değildir.

CLS uyumlu alternatif
System.Int32.Parse(String)

Belirtilen kültüre özgü biçimdeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

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

Parametreler

s
String

Dönüştürülecek sayıyı temsil eden bir dize.

provider
IFormatProvider

hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

içinde sbelirtilen sayıya eşdeğer bir 16 bit işaretsiz tamsayı.

Uygulamalar

Öznitelikler

Özel durumlar

s, null değeridir.

s doğru biçimde değil.

sUInt16.MinValue değerinden küçük veya UInt16.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, pozitif işareti olarak iki artı işareti (++) kullanan özel bir kültürün örneğini oluşturur. Daha sonra hem bu özel kültürü hem de sabit kültürü temsil eden nesneleri kullanarak CultureInfo bir dize dizisini ayrıştırmak için yöntemini çağırırParse(String, IFormatProvider).

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define a custom culture that uses "++" as a positive sign. 
      CultureInfo ci = new CultureInfo("");
      ci.NumberFormat.PositiveSign = "++";
      // Create an array of cultures.
      CultureInfo[] cultures = { ci, CultureInfo.InvariantCulture };
      // Create an array of strings to parse.
      string[] values = { "++1403", "-0", "+0", "+16034", 
                          Int16.MinValue.ToString(), "14.0", "18012" };
      // Parse the strings using each culture.
      foreach (CultureInfo culture in cultures)
      {
         Console.WriteLine("Parsing with the '{0}' culture.", culture.Name);
         foreach (string value in values)
         {
            try {
               ushort number = UInt16.Parse(value, culture);
               Console.WriteLine("   Converted '{0}' to {1}.", value, number);
            }
            catch (FormatException) {
               Console.WriteLine("   The format of '{0}' is invalid.", value);
            }
            catch (OverflowException) {
               Console.WriteLine("   '{0}' is outside the range of a UInt16 value.", value);
            }               
         }
      }
   }
}
// The example displays the following output:
//       Parsing with the  culture.
//          Converted '++1403' to 1403.
//          Converted '-0' to 0.
//          The format of '+0' is invalid.
//          The format of '+16034' is invalid.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
//       Parsing with the '' culture.
//          The format of '++1403' is invalid.
//          Converted '-0' to 0.
//          Converted '+0' to 0.
//          Converted '+16034' to 16034.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
open System
open System.Globalization

// Define a custom culture that uses "++" as a positive sign. 
let ci = CultureInfo ""
ci.NumberFormat.PositiveSign <- "++"
// Create an array of cultures.
let cultures = [| ci; CultureInfo.InvariantCulture |]
// Create an array of strings to parse.
let values = 
    [| "++1403"; "-0"; "+0"; "+16034" 
       string Int16.MinValue; "14.0"; "18012" |]
// Parse the strings using each culture.
for culture in cultures do
    printfn $"Parsing with the '{culture.Name}' culture."
    for value in values do
        try
            let number = UInt16.Parse(value, culture)
            printfn $"   Converted '{value}' to {number}."
        with
        | :? FormatException ->
            printfn $"   The format of '{value}' is invalid."
        | :? OverflowException ->
            printfn $"   '{value}' is outside the range of a UInt16 value."
// The example displays the following output:
//       Parsing with the  culture.
//          Converted '++1403' to 1403.
//          Converted '-0' to 0.
//          The format of '+0' is invalid.
//          The format of '+16034' is invalid.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
//       Parsing with the '' culture.
//          The format of '++1403' is invalid.
//          Converted '-0' to 0.
//          Converted '+0' to 0.
//          Converted '+16034' to 16034.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define a custom culture that uses "++" as a positive sign. 
      Dim ci As CultureInfo = New CultureInfo("")
      ci.NumberFormat.PositiveSign = "++"
      ' Create an array of cultures.
      Dim cultures() As CultureInfo = { ci, CultureInfo.InvariantCulture }
      ' Create an array of strings to parse.
      Dim values() As String = { "++1403", "-0", "+0", "+16034", _
                                 Int16.MinValue.ToString(), "14.0", "18012" }
      ' Parse the strings using each culture.
      For Each culture As CultureInfo In cultures
         Console.WriteLine("Parsing with the '{0}' culture.", culture.Name)
         For Each value As String In values
            Try
               Dim number As UShort = UInt16.Parse(value, culture)
               Console.WriteLine("   Converted '{0}' to {1}.", value, number)
            Catch e As FormatException
               Console.WriteLine("   The format of '{0}' is invalid.", value)
            Catch e As OverflowException
               Console.WriteLine("   '{0}' is outside the range of a UInt16 value.", value)
            End Try               
         Next
      Next
   End Sub
End Module
' The example displays the following output:
'       Parsing with the  culture.
'          Converted '++1403' to 1403.
'          Converted '-0' to 0.
'          The format of '+0' is invalid.
'          The format of '+16034' is invalid.
'          '-32768' is outside the range of a UInt16 value.
'          The format of '14.0' is invalid.
'          Converted '18012' to 18012.
'       Parsing with the '' culture.
'          The format of '++1403' is invalid.
'          Converted '-0' to 0.
'          Converted '+0' to 0.
'          Converted '+16034' to 16034.
'          '-32768' is outside the range of a UInt16 value.
'          The format of '14.0' is invalid.
'          Converted '18012' to 18012.

Açıklamalar

s parametresi formun bir sayısını içerir:

[ws] [sign] rakamlar[ws]

Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tablo her öğeyi açıklar.

Öğe Açıklama
ws İsteğe bağlı beyaz boşluk.
sign İsteğe bağlı bir işaret veya sıfır değerini temsil eden s negatif bir işaret.
rakamlar 0 İle 9 arasında değişen bir basamak dizisi.

s parametresi, stil kullanılarak NumberStyles.Integer yorumlanır. Bayt değerinin ondalık basamaklarına ek olarak, yalnızca baştaki ve sondaki boşluklara ve baştaki işaretine izin verilir. (Negatif işareti varsa, s sıfır değerini temsil etmelidir veya yöntem bir OverflowExceptionoluşturur.) stil öğelerini içinde bulunabilecek skültüre özgü biçimlendirme bilgileriyle birlikte açıkça tanımlamak için yöntemini kullanın Parse(String, NumberStyles, IFormatProvider) .

provider parametresi, yöntemi biçimi hakkında kültüre özgü bilgiler sağlayan bir nesnesi döndüren bir IFormatProviderNumberFormatInfo uygulamadır GetFormats. Ayrıştırma işlemine provider özel biçimlendirme bilgileri sağlamak için parametresini kullanmanın üç yolu vardır:

  • Biçimlendirme bilgileri sağlayan gerçek NumberFormatInfo nesneyi geçirebilirsiniz. (Uygulaması GetFormat basitçe kendini döndürür.)

  • Biçimlendirmesi kullanılacak kültürü belirten bir CultureInfo nesne geçirebilirsiniz. Özelliği NumberFormat biçimlendirme bilgileri sağlar.

  • Özel IFormatProvider bir uygulama geçirebilirsiniz. GetFormat Yöntemi, biçimlendirme bilgileri sağlayan nesneyi örneklemeli ve döndürmelidirNumberFormatInfo.

ise providernull, NumberFormatInfo geçerli kültür için kullanılır.

Ayrıca bkz.

Şunlara uygulanır

Parse(String, NumberStyles)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen stildeki bir sayının dize gösterimini 16 bit işaretsiz tamsayı eşdeğerine dönüştürür.

Bu yöntem CLS uyumlu değildir. CLS uyumlu alternatif: Parse(String, NumberStyles).

public:
 static System::UInt16 Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static ushort Parse (string s, System.Globalization.NumberStyles style);
public static ushort Parse (string s, System.Globalization.NumberStyles style);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles -> uint16
static member Parse : string * System.Globalization.NumberStyles -> uint16
Public Shared Function Parse (s As String, style As NumberStyles) As UShort

Parametreler

s
String

Dönüştürülecek sayıyı temsil eden bir dize. Dize, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.

style
NumberStyles

İzin verilen biçimini belirten numaralandırma değerlerinin bit düzeyinde birleşimi s. Belirtilmesi gereken tipik bir değerdir Integer.

Döndürülenler

içinde sbelirtilen sayıya eşdeğer bir 16 bit işaretsiz tamsayı.

Öznitelikler

Özel durumlar

s, null değeridir.

style bir NumberStyles değer değildir.

-veya-

styleve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.

s ile styleuyumlu bir biçimde değil.

sUInt16.MinValue değerinden küçük veya UInt16.MaxValue değerinden büyük bir sayıyı temsil eder.

-veya-

s sıfır olmayan kesirli basamaklar içerir.

Örnekler

Aşağıdaki örnek, bir dizi NumberStyles değer kullanarak bir dize dizisindeki her öğeyi ayrıştırmaya çalışır.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values = { " 214 ", "1,064", "(0)", "1241+", " + 214 ", " +214 ", "2153.0", "1e03", "1300.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 {
               ushort number = UInt16.Parse(value, style);
               Console.WriteLine("   {0}: {1}", style, number);
            }   
            catch (FormatException) {
               Console.WriteLine("   {0}: Bad Format", style);
            }
         }
         Console.WriteLine();
      }
   }
}
// The example display the following output:
//    Attempting to convert ' 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064
//       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 '1241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 1241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '2153.0':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 2153
//    
//    Attempting to convert '1e03':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 1000
//    
//    Attempting to convert '1300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 13
open System
open System.Globalization

let values = [| " 214 "; "1,064"; "(0)"; "1241+"; " + 214 "; " +214 "; "2153.0"; "1e03"; "1300.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 = UInt16.Parse(value, style)
            printfn $"   {style}: {number}"
        with :? FormatException ->
            printfn $"   {style}: Bad Format"
    printfn ""
// The example display the following output:
//    Attempting to convert ' 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064
//       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 '1241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 1241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '2153.0':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 2153
//    
//    Attempting to convert '1e03':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 1000
//    
//    Attempting to convert '1300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 13
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { " 214 ", "1,064", "(0)", "1241+", " + 214 ", " +214 ", "2153.0", "1e03", "1300.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 UShort = UInt16.Parse(value, style)
               Console.WriteLine("   {0}: {1}", style, number)
            Catch e As FormatException
               Console.WriteLine("   {0}: Bad Format", style)
            End Try         
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    Attempting to convert ' 214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: 214
'       Integer, AllowTrailingSign: 214
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '1,064':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: 1064
'       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 '1241+':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 1241
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' + 214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' +214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 214
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '2153.0':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 2153
'    
'    Attempting to convert '1e03':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 1000
'    
'    Attempting to convert '1300.0e-2':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 13

Açıklamalar

style parametresi, ayrıştırma işleminin başarılı olması için parametrede s izin verilen stil öğelerini (boşluk, pozitif veya negatif işaret simgesi, grup ayırıcı simgesi veya ondalık ayırıcı simgesi gibi) tanımlar. style sabit listesindeki bit bayraklarının NumberStyles bir bileşimi olmalıdır. parametresi, tarafından temsil s edilen style sayı sistemi (ondalık veya onaltılık) yalnızca çalışma zamanında bilindiğinde veya içinde boşluk veya işaret simgesine izin vermek istemediğinizde, onaltılık değerin dize gösterimini içerdiğinde sbu yöntem aşırı yüklemesini kullanışlı s hale getirir.

değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:

[ws] [$][sign][rakamlar,]rakamlar[.fractional_digits][E[sign]exponential_digits][ws]

Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. içeriyorsa styleNumberStyles.AllowHexSpecifiers, parametresi aşağıdaki öğeleri içerebilir:

[ws] hexdigits[ws]

Aşağıdaki tablo her öğeyi açıklar.

Öğe Açıklama
Ws İsteğe bağlı beyaz boşluk. Bayrağı içeriyorsa başında boşluk ve sstyle bayrağı içeriyorsa sonunda sstyleNumberStyles.AllowTrailingWhite görüntülenebilir.NumberStyles.AllowLeadingWhite
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyNegativePattern ve NumberFormatInfo.CurrencyPositivePattern özellikleri tarafından tanımlanır. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowCurrencySymbol para birimi simgesi içinde sstyle görünebilir.
sign İsteğe bağlı bir işaret. İşaret, bayrağı içeriyorsa başında sstyle ve bayrağını içeriyorsa NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign sonunda sstyle görüntülenebilir. Parantezler, bayrağı içeriyorsa NumberStyles.AllowParentheses negatif bir değeri style belirtmek için içinde kullanılabilirs. Ancak, negatif işareti simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur.
Basamak

fractional_digits

exponential_digits
0 İle 9 arasında bir basamak dizisi. fractional_digits için yalnızca 0 rakamı geçerlidir.
, Kültüre özgü bir grup ayırıcı simge. bayrağını style içeriyorsa geçerli kültürün grup ayırıcısı NumberStyles.AllowThousands içinde s görüntülenebilir.
. Bir kültüre özgü ondalık nokta sembolü. bayrağını style içeriyorsa geçerli kültürün NumberStyles.AllowDecimalPoint ondalık noktası simgesi içinde s görüntülenebilir. Ayrıştırma işleminin başarılı olması için kesirli basamak olarak yalnızca 0 rakamı görüntülenebilir; fractional_digits başka bir rakam içeriyorsa, bir FormatException oluşturulur.
E Değerin üslü (bilimsel) gösterimle temsil edildiğini gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa üstel gösteriminde style bir sayıyı NumberStyles.AllowExponent temsil edebilir.
hexdigits 0 İle f veya 0 ile f arasında onaltılık basamak dizisi.

Not

içindeki s sonlandırıcı NUL (U+0000) karakterleri, bağımsız değişkenin değerinden style bağımsız olarak ayrıştırma işlemi tarafından yoksayılır.

Yalnızca basamak içeren bir dize (stile NumberStyles.None karşılık gelir) türün aralığındaysa UInt16 her zaman başarıyla ayrıştırılır. Kalan NumberStyles üyelerin çoğu giriş dizesinde mevcut olabilecek ancak mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tablo, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediğini gösterir.

NumberStyles Değer Basamaklara ek olarak izin verilen s öğeler
None Yalnızca rakamlar öğesi.
AllowDecimalPoint Ondalık ayırıcı (.) ve kesirli basamaklar öğeleri.
AllowExponent Exponential_digits ile birlikte üstel gösterimi gösteren "e" veya "E" karakteri.
AllowLeadingWhite başındaki sws öğesi.
AllowTrailingWhite sonundaki sws öğesi.
AllowLeadingSign başındaki ssign öğesi.
AllowTrailingSign sonundaki ssign öğesi.
AllowParentheses Sayısal değeri kapsayan parantez biçimindeki işaret öğesi.
AllowThousands Grup ayırıcı (,) öğesi.
AllowCurrencySymbol Para birimi ($) öğesi.
Currency Tüm öğeler. Ancak, s onaltılık bir sayıyı veya üstel gösterimindeki bir sayıyı temsil edemez.
Float öğesinin başında veya sonundaki sws öğesi, başlangıcını sve ondalık ayırıcı (.) simgesini imzalar. parametresi üstel s gösterimi de kullanabilir.
Number , , grup ayırıcısı (,) ve ondalık ayırıcı (.) öğeleri. signws
Any Tüm öğeler. Ancak, s onaltılık bir sayıyı temsil edemez.

içinde belirli stil öğelerinin NumberStyles.AllowHexSpecifiersbulunmasına izin veren ancak gerektirmeyen diğer NumberStyles değerlerden farklı olarak, stil değeri içindeki tek tek sayısal karakterlerin s her zaman onaltılık karakterler olarak yorumlandığı anlamına gelir. Geçerli onaltılı karakter 0-9, A-F ve a-f karakterleridir. "0x" gibi bir ön ek desteklenmez ve ayrıştırma işleminin başarısız olmasına neden olur. parametresiyle style birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik bir sayı stili NumberStyles.HexNumberiçerir.)

Not

Onaltılık bir sayının dize gösterimi ises, bunun önünde onaltılık sayı olarak ayırt eden herhangi bir dekorasyon (veya &hgibi0x) olamaz. Bu dönüştürmenin başarısız olmasına neden olur.

s parametresi, geçerli sistem kültürü için başlatılan bir NumberFormatInfo nesnedeki biçimlendirme bilgileri kullanılarak ayrıştırılır. Biçimlendirme bilgileri ayrıştırma işlemi için kullanılan kültürü belirtmek için aşırı yüklemeyi çağırın Parse(String, NumberStyles, IFormatProvider) .

Ayrıca bkz.

Şunlara uygulanır

Parse(ReadOnlySpan<Char>, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Bir karakter aralığını bir değere ayrıştırıyor.

public:
 static System::UInt16 Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::UInt16>::Parse;
public static ushort Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> uint16
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As UShort

Parametreler

s
ReadOnlySpan<Char>

Ayrıştırılacak karakterlerin yayılması.

provider
IFormatProvider

hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

ayrıştırma ssonucu.

Uygulamalar

Şunlara uygulanır

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs

UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.

public:
 static System::UInt16 Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::UInt16>::Parse;
public static ushort Parse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> uint16
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As UShort

Parametreler

utf8Text
ReadOnlySpan<Byte>

Ayrıştırılacak UTF-8 karakter aralığı.

provider
IFormatProvider

hakkında utf8Textkültüre özgü biçimlendirme bilgileri sağlayan bir nesne.

Döndürülenler

ayrıştırma utf8Textsonucu.

Uygulamalar

Şunlara uygulanır

Parse(String)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Önemli

Bu API, CLS uyumlu değildir.

CLS uyumlu alternatif
System.Int32.Parse(String)

Bir sayının dize gösterimini 16 bitlik işaretsiz tamsayı eşdeğerine dönüştürür.

public:
 static System::UInt16 Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static ushort Parse (string s);
public static ushort Parse (string s);
[<System.CLSCompliant(false)>]
static member Parse : string -> uint16
static member Parse : string -> uint16
Public Shared Function Parse (s As String) As UShort

Parametreler

s
String

Dönüştürülecek sayıyı temsil eden bir dize.

Döndürülenler

içinde bulunan ssayıya eşdeğer bir 16 bit işaretsiz tamsayı.

Öznitelikler

Özel durumlar

s, null değeridir.

s doğru biçimde değil.

sUInt16.MinValue değerinden küçük veya UInt16.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, bir dize dizisindeki her öğeyi işaretsiz bir 16 bit tamsayıya dönüştürmek için yöntemini çağırır Parse(String) .

using System;

public class Example
{
   public static void Main()
   {
      string[] values = { "-0", "17", "-12", "185", "66012", "+0", 
                          "", null, "16.1", "28.0", "1,034" };
      foreach (string value in values)
      {
         try {
            ushort number = UInt16.Parse(value);
            Console.WriteLine("'{0}' --> {1}", value, number);
         }
         catch (FormatException) {
            Console.WriteLine("'{0}' --> Bad Format", value);
         }
         catch (OverflowException) {   
            Console.WriteLine("'{0}' --> OverflowException", value);
         }
         catch (ArgumentNullException) {
            Console.WriteLine("'{0}' --> Null", value);
         }
      }                                 
   }
}
// The example displays the following output:
//       '-0' --> 0
//       '17' --> 17
//       '-12' --> OverflowException
//       '185' --> 185
//       '66012' --> OverflowException
//       '+0' --> 0
//       '' --> Bad Format
//       '' --> Null
//       '16.1' --> Bad Format
//       '28.0' --> Bad Format
//       '1,034' --> Bad Format
open System

let values = 
    [| "-0"; "17"; "-12"; "185"; "66012"; "+0" 
       ""; null; "16.1"; "28.0"; "1,034" |]
for value in values do
    try
        let number = UInt16.Parse value
        printfn $"'{value}' --> {number}"
    with
    | :? FormatException ->
        printfn $"'{value}' --> Bad Format"
    | :? OverflowException ->
        printfn $"'{value}' --> OverflowException"
    | :? ArgumentNullException ->
        printfn $"'{value}' --> Null"
// The example displays the following output:
//       '-0' --> 0
//       '17' --> 17
//       '-12' --> OverflowException
//       '185' --> 185
//       '66012' --> OverflowException
//       '+0' --> 0
//       '' --> Bad Format
//       '' --> Null
//       '16.1' --> Bad Format
//       '28.0' --> Bad Format
//       '1,034' --> Bad Format
Module Example
   Public Sub Main()
      Dim values() As String = { "-0", "17", "-12", "185", "66012", _ 
                                 "+0", "", Nothing, "16.1", "28.0", _
                                 "1,034" }
      For Each value As String In values
         Try
            Dim number As UShort = UInt16.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}' --> OverflowException", value)
         Catch e As ArgumentNullException
            Console.WriteLine("'{0}' --> Null", value)
         End Try
      Next                                 
   End Sub
End Module
' The example displays the following output:
'       '-0' --> 0
'       '17' --> 17
'       '-12' --> OverflowException
'       '185' --> 185
'       '66012' --> OverflowException
'       '+0' --> 0
'       '' --> Bad Format
'       '' --> Null
'       '16.1' --> Bad Format
'       '28.0' --> Bad Format
'       '1,034' --> Bad Format

Açıklamalar

parametresi, s aşağıdaki biçimdeki bir sayının dize gösterimi olmalıdır.

[ws] [sign] rakamlar[ws]

Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tablo her öğeyi açıklar.

Öğe Açıklama
Ws İsteğe bağlı beyaz boşluk.
sign İsteğe bağlı bir işaret. Geçerli işaret karakterleri geçerli kültürün NumberFormatInfo.NegativeSign ve NumberFormatInfo.PositiveSign özellikleri tarafından belirlenir. Ancak, negatif işareti simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur.
Basamak 0 İle 9 arasında değişen bir basamak dizisi. Baştaki sıfırlar dikkate alınmaz.

Not

parametresi tarafından s belirtilen dize, stil kullanılarak NumberStyles.Integer yorumlanır. Herhangi bir grup ayırıcısı veya ondalık ayırıcı içeremez ve ondalık bölümü olamaz.

s parametresi, geçerli sistem kültürü için başlatılan bir System.Globalization.NumberFormatInfo nesnedeki biçimlendirme bilgileri kullanılarak ayrıştırılır. Daha fazla bilgi için bkz. NumberFormatInfo.CurrentInfo. Belirli bir kültürün biçimlendirme bilgilerini kullanarak bir dizeyi ayrıştırmak için yöntemini kullanın Parse(String, IFormatProvider) .

Ayrıca bkz.

Şunlara uygulanır