Aracılığıyla paylaş


Int16.Parse Yöntem

Tanım

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

Aşırı Yüklemeler

Name Description
Parse(String, NumberStyles, IFormatProvider)

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

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Bir sayının belirtilen stilde ve kültüre özgü biçimdeki span gösterimini 16 bit imzalı 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)

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

Parse(String)

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

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, NumberStyles)

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

Parse(String, NumberStyles, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public:
 static short Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
 static short Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<short>::Parse;
public static short Parse(string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static short Parse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> int16
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As Short

Parametreler

s
String

Dönüştürülecek bir sayı içeren dize.

style
NumberStyles

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

provider
IFormatProvider

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

Döndürülenler

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

Uygulamalar

Özel durumlar

s, null'e eşittir.

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.

s Int16.MinValue değerinden küçük veya Int16.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, değerlerin style dize gösterimlerini Int16 ayrıştırmak için çeşitli ve provider parametreleri kullanır.

string value;
short number;
NumberStyles style;
CultureInfo provider;

// Parse string using "." as the thousands separator
// and " " as the decimal separator.
value = "19 694,00";
style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
provider = new CultureInfo("fr-FR");

number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '19 694,00' converted to 19694.

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '19 694,00'.

// Parse string using "$" as the currency symbol for en_GB and
// en-US cultures.
value = "$6,032.00";
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
provider = new CultureInfo("en-GB");

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '$6,032.00'.

provider = new CultureInfo("en-US");
number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '$6,032.00' converted to 6032.
// Parse string using "." as the thousands separator
// and " " as the decimal separator.
let value = "19 694,00"
let style = NumberStyles.AllowDecimalPoint ||| NumberStyles.AllowThousands
let provider = CultureInfo "fr-FR"

let number = Int16.Parse(value, style, provider)
printfn $"'{value}' converted to {number}." 
// Displays:
//    '19 694,00' converted to 19694.

try
    let number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
    printfn $"'{value}' converted to {number}." 
with :? FormatException ->
    printfn $"Unable to parse '{value}'."
// Displays:
//    Unable to parse '19 694,00'.

// Parse string using "$" as the currency symbol for en_GB and
// en-US cultures.
let value = "$6,032.00"
let style = NumberStyles.Number ||| NumberStyles.AllowCurrencySymbol

try
    let number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
    printfn $"'{value}' converted to {number}." 
with :? FormatException ->
    printfn $"Unable to parse '{value}'."
// Displays:
//    Unable to parse '$6,032.00'.

let provider = CultureInfo "en-US"
let number = Int16.Parse(value, style, provider)
printfn $"'{value}' converted to {number}."
// Displays:
//    '$6,032.00' converted to 6032.
Dim value As String
Dim number As Short
Dim style As NumberStyles
Dim provider As CultureInfo

' Parse string using "." as the thousands separator 
' and " " as the decimal separator.
value = "19 694,00"
style = NumberStyles.AllowDecimalPoint Or NumberStyles.AllowThousands
provider = New CultureInfo("fr-FR")

number = Int16.Parse(value, style, provider)
Console.WriteLine("'{0}' converted to {1}.", value, number)
' Displays:
'    '19 694,00' converted to 19694.

Try
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
   Console.WriteLine("'{0}' converted to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Displays:
'    Unable to parse '19 694,00'.

' Parse string using "$" as the currency symbol for en_GB and
' en-US cultures.
value = "$6,032.00"
style = NumberStyles.Number Or NumberStyles.AllowCurrencySymbol
provider = New CultureInfo("en-GB")

Try
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture)
   Console.WriteLine("'{0}' converted to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Displays:
'    Unable to parse '$6,032.00'.
                        
provider = New CultureInfo("en-US")
number = Int16.Parse(value, style, provider)
Console.WriteLine("'{0}' converted to {1}.", value, number)
' Displays:
'    '$6,032.00' converted to 6032.

Açıklamalar

parametresi, style ayrıştırma işleminin başarılı olması için parametresinde s izin verilen stil öğelerini (boşluk veya pozitif işaret gibi) tanımlar. Numaralandırmadaki NumberStyles bit bayraklarının bir bileşimi olmalıdır. değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:

[ws] [$] [sign] [rakamlar,]rakamlar[.fractional_digits][e[sign]digits][ws]

Veya şunu style içeriyorsa AllowHexSpecifier:

[ws]hexdigits[ws]

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

Öğe Açıklama
Ws İsteğe bağlı boşluk. Boşluk, bayrağı içeriyorsa başında s veya bayrağı içeriyorsa sonunda NumberStyles.AllowTrailingWhitesstyle görüntülenebilir.styleNumberStyles.AllowLeadingWhite
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyPositivePattern ve NumberFormatInfo.CurrencyNegativePattern özellikleri tarafından tanımlanır. Bayrağı içeriyorsa geçerli kültürün s para birimi simgesi içinde styleNumberStyles.AllowCurrencySymbol görüntülenebilir.
imza İsteğe bağlı bir işaret. İşaret, bayrağın eklenip eklenmediğinin başında ve bayrağın eklenip eklenmediğinin styleNumberStyles.AllowTrailingSigns sonunda görünebilir.sstyleNumberStyles.AllowLeadingSign Parantezler, bayrağı içeriyorsa s negatif bir değeri style belirtmek için içinde kullanılabilirNumberStyles.AllowParentheses.
Basamak 0 ile 9 arasında bir basamak dizisi.
, Kültüre özgü binlik ayırıcı simgesi. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowThousands binlik ayırıcı simgesi içinde görüntülenebilir.styles
. Kültüre özgü ondalık nokta simgesi. Bayrağı içeriyorsa geçerli kültürün s ondalık noktası simgesi içinde styleNumberStyles.AllowDecimalPoint görüntülenebilir.
fractional_digits 0 basamaklı bir dizi. Bayrağı içeriyorsa NumberStyles.AllowDecimalPoint kesirli basamaklar içinde sstyle görüntülenebilir. fractional_digits'de 0 dışında bir basamak görünürse, yöntemi bir OverflowExceptionoluşturur.
e Üstel gösterimde temsil edilebileceğini gösteren s 'e' veya 'E' karakteri. parametresi, s bayrağını içeriyorsa üstel gösterimde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. Ancak parametresi, s veri türü aralığındaki Int16 bir sayıyı temsil etmelidir ve sıfır olmayan kesirli bileşene sahip olamaz.
hexdigits 0'dan f'ye veya 0'dan F'ye kadar 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) her zaman başarıyla ayrıştırılıyor. Kalan NumberStyles üyelerin çoğu, bu giriş dizesinde mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tablo, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediğini gösterir.

Bileşik olmayan NumberStyles değerleri Basamaklara ek olarak s içinde izin verilen öğeler
NumberStyles.None Yalnızca ondalık basamaklar.
NumberStyles.AllowDecimalPoint . ve fractional_digits öğeleri. Ancak , fractional_digits yalnızca bir veya daha fazla 0 basamak içermelidir veya bir OverflowException oluşturulur.
NumberStyles.AllowExponent parametresi üstel s gösterim de kullanabilir.
NumberStyles.AllowLeadingWhite başındaki sws öğesi.
NumberStyles.AllowTrailingWhite sonundaki s öğesi.
NumberStyles.AllowLeadingSign Basamakların önünde bir işaret görünebilir.
NumberStyles.AllowTrailingSign Basamakların ardından bir işaret görünebilir.
NumberStyles.AllowParentheses Sayısal değeri kapsayan parantez biçimindeki sign öğesi.
NumberStyles.AllowThousands öğesi.
NumberStyles.AllowCurrencySymbol $ öğesi.

NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s ön ek olmadan onaltılık değerin dize gösterimi olmalıdır. Örneğin, "9AF3" başarıyla ayrıştırıyor, ancak "0x9AF3" ayrıştırmıyor.. içinde style bulunabilecek diğer bayraklar yalnızca ve NumberStyles.AllowLeadingWhite'tirNumberStyles.AllowTrailingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik bir sayı stiline NumberStyles.HexNumbersahiptir.)

provider parametresi, yöntemi bir nesnesi alan bir IFormatProviderNumberFormatInfo uygulamadırGetFormat. nesnesi, NumberFormatInfo biçimi shakkında kültüre özgü bilgiler sağlar. ise providernull, NumberFormatInfo geçerli kültürün nesnesi kullanılır.

Ayrıca bkz.

Şunlara uygulanır

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public static short Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
public static short Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> int16
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As Short

Parametreler

s
ReadOnlySpan<Char>

Dönüştürülecek sayıyı temsil eden karakterleri içeren bir yayılma alanı.

style
NumberStyles

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

provider
IFormatProvider

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

Döndürülenler

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

Uygulamalar

Şunlara uygulanır

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

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

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 utf8Textişleminin sonucu.

Uygulamalar

Şunlara uygulanır

Parse(String, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public:
 static short Parse(System::String ^ s, IFormatProvider ^ provider);
public:
 static short Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<short>::Parse;
public static short Parse(string s, IFormatProvider provider);
public static short Parse(string s, IFormatProvider? provider);
static member Parse : string * IFormatProvider -> int16
Public Shared Function Parse (s As String, provider As IFormatProvider) As Short

Parametreler

s
String

Dönüştürülecek bir sayı içeren dize.

provider
IFormatProvider

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

Döndürülenler

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

Uygulamalar

Özel durumlar

s, null'e eşittir.

s doğru biçimde değil.

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

Örnekler

Aşağıdaki örnek, değerlerin Int16 dize gösterimlerini yöntemiyle Int16.Parse(String, IFormatProvider) ayrıştırmaktadır.

string stringToConvert;
short number;

stringToConvert = " 214 ";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}

stringToConvert = " + 214";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}

stringToConvert = " +214 ";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}
// The example displays the following output to the console:
//       Converted ' 214 ' to 214.
//       Unable to parse ' + 214'.
//       Converted ' +214 ' to 214.
let stringToConvert = " 214 "
try
    let number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
    printfn $"Converted '{stringToConvert}' to {number}." 
with 
| :? FormatException ->
    printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
    printfn $"'{stringToConvert}' is out of range of the Int16 data type."

let stringToConvert = " + 214"
try
    let number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
    printfn $"Converted '{stringToConvert}' to {number}." 
with 
| :? FormatException ->
    printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException -> 
    printfn $"'{stringToConvert}' is out of range of the Int16 data type."

let stringToConvert = " +214 "
try
    let number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
    printfn $"Converted '{stringToConvert}' to {number}." 
with
| :? FormatException ->
    printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
    printfn $"'{stringToConvert}' is out of range of the Int16 data type."

// The example displays the following output to the console:
//       Converted ' 214 ' to 214.
//       Unable to parse ' + 214'.
//       Converted ' +214 ' to 214.
Dim stringToConvert As String
Dim number As Short

stringToConvert = " 214 "
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try

stringToConvert = " + 214"                                 
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try

stringToConvert = " +214 " 
Try
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture)
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
Catch e As FormatException
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
   Console.WriteLine("'{0'} is out of range of the Int16 data type.", _
                     stringToConvert)
End Try
' The example displays the following output to the console:
'       Converted ' 214 ' to 214.
'       Unable to parse ' + 214'.
'       Converted ' +214 ' to 214.

Açıklamalar

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

[ws] [sign]digits[ws]

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

Öğe Açıklama
Ws İsteğe bağlı bir boşluk.
işaret İsteğe bağlı bir işaret.
Basamak 0 ile 9 arasında bir basamak dizisi.

s parametresi stil kullanılarak NumberStyles.Integer yorumlanır. Ondalık basamaklara ek olarak, içinde syalnızca baştaki ve sondaki boşlukların önünde işareti olmasına izin verilir. stil öğelerini içinde bulunabilecek skültüre özgü biçimlendirme bilgileriyle birlikte açıkça tanımlamak için yöntemini kullanın Int16.Parse(String, NumberStyles, IFormatProvider) .

provider parametresi, bir nesne alan bir IFormatProviderNumberFormatInfo uygulamadır. biçimi NumberFormatInfo hakkında kültüre sözgü bilgiler sağlar. ise providernull, NumberFormatInfo geçerli kültür için kullanılır.

Ayrıca bkz.

Şunlara uygulanır

Parse(String)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public:
 static short Parse(System::String ^ s);
public static short Parse(string s);
static member Parse : string -> int16
Public Shared Function Parse (s As String) As Short

Parametreler

s
String

Dönüştürülecek bir sayı içeren dize.

Döndürülenler

içinde bulunan sayıya eşdeğer 16 bit imzalı stamsayı.

Özel durumlar

s, null'e eşittir.

s doğru biçimde değil.

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

Örnekler

Aşağıdaki örnekte, yöntemini kullanarak bir dize değerinin 16 bit imzalı tamsayı değerine nasıl dönüştürüldüğü gösterilmektedir Int16.Parse(String) . Sonuçta elde edilen tamsayı değeri konsolda görüntülenir.

string value;
short number;

value = " 12603 ";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}

value = " 16,054";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}

value = " -17264";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}
// The example displays the following output to the console:
//       Converted ' 12603 ' to 12603.
//       Unable to convert ' 16,054' to a 16-bit signed integer.
//       Converted ' -17264' to -17264.
let value = " 12603 "
try
    let number = Int16.Parse value
    printfn $"Converted '{value}' to {number}." 
with :? FormatException -> 
    printfn $"Unable to convert '{value}' to a 16-bit signed integer."

let value = " 16,054"
try
    let number = Int16.Parse value
    printfn $"Converted '{value}' to {number}."
with :? FormatException ->
    printfn "Unable to convert '{value}' to a 16-bit signed integer."
                    
let value = " -17264"
try
    let number = Int16.Parse value
    printfn $"Converted '{value}' to {number}."
with :? FormatException ->
    printfn "Unable to convert '{value}' to a 16-bit signed integer."
    

// The example displays the following output to the console:
//       Converted ' 12603 ' to 12603.
//       Unable to convert ' 16,054' to a 16-bit signed integer.
//       Converted ' -17264' to -17264.
Dim value As String
Dim number As Short

value = " 12603 "
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try

value = " 16,054"
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try
                        
value = " -17264"
Try
   number = Short.Parse(value)
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.", _
                     value)
End Try
' The example displays the following output to the console:
'       Converted ' 12603 ' to 12603.
'       Unable to convert ' 16,054' to a 16-bit signed integer.
'       Converted ' -17264' to -17264.

Açıklamalar

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

[ws] [sign]digits[ws]

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

Öğe Açıklama
Ws İsteğe bağlı boşluk.
imza İsteğe bağlı bir işaret.
Basamak 0 ile 9 arasında bir basamak dizisi.

s parametresi stil kullanılarak NumberStyles.Integer yorumlanır. Tamsayı değerinin ondalık basamaklarına ek olarak, yalnızca baştaki ve sondaki boşlukların baştaki işaretiyle birlikte kullanılmasına izin verilir. içinde sbulunabilecek stil öğelerini açıkça tanımlamak için veya Parse yöntemini kullanınInt16.Parse(String, NumberStyles).

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. Daha fazla bilgi için bkz. CurrentInfo. Başka bir kültürün biçimlendirme bilgilerini kullanarak bir dizeyi ayrıştırmak için veya Int16.Parse(String, NumberStyles, IFormatProvider) yöntemini kullanınInt16.Parse(String, IFormatProvider).

Ayrıca bkz.

Şunlara uygulanır

Parse(ReadOnlySpan<Char>, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public:
 static short Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<short>::Parse;
public static short Parse(ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> int16
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As Short

Parametreler

s
ReadOnlySpan<Char>

Ayrıştırılacak karakterlerin yayılma alanı.

provider
IFormatProvider

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

Döndürülenler

ayrıştırma sişleminin sonucu.

Uygulamalar

Şunlara uygulanır

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

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

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 utf8Textişleminin sonucu.

Uygulamalar

Şunlara uygulanır

Parse(String, NumberStyles)

Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs
Kaynak:
Int16.cs

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

public:
 static short Parse(System::String ^ s, System::Globalization::NumberStyles style);
public static short Parse(string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> int16
Public Shared Function Parse (s As String, style As NumberStyles) As Short

Parametreler

s
String

Dönüştürülecek bir sayı içeren dize.

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.

Döndürülenler

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

Özel durumlar

s, null'e eşittir.

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.

s Int16.MinValue değerinden küçük veya Int16.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, Int16.Parse(String, NumberStyles) en-US kültürünü kullanarak değerlerin Int16 dize gösterimlerini ayrıştırmak için yöntemini kullanır.

using System;
using System.Globalization;

public class ParseSample
{
   public static void Main()
   {
      string value;
      NumberStyles style;

      // Parse a number with a thousands separator (throws an exception).
      value = "14,644";
      style = NumberStyles.None;
      ParseToInt16(value, style);

      style = NumberStyles.AllowThousands;
      ParseToInt16(value, style);

      // Parse a number with a thousands separator and decimal point.
      value = "14,644.00";
      style = NumberStyles.AllowThousands | NumberStyles.Integer |
              NumberStyles.AllowDecimalPoint;
      ParseToInt16(value, style);

      // Parse a number with a fractional component (throws an exception).
      value = "14,644.001";
      ParseToInt16(value, style);

      // Parse a number in exponential notation.
      value = "145E02";
      style = style | NumberStyles.AllowExponent;
      ParseToInt16(value, style);

      // Parse a number in exponential notation with a positive sign.
      value = "145E+02";
      ParseToInt16(value, style);

      // Parse a number in exponential notation with a negative sign
      // (throws an exception).
      value = "145E-02";
      ParseToInt16(value, style);
   }

   private static void ParseToInt16(string value, NumberStyles style)
   {
      try
      {
         short number = Int16.Parse(value, style);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to parse '{0}' with style {1}.", value,
                           style.ToString());
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range of the Int16 type.", value);
      }
   }
}
// The example displays the following output to the console:
//       Unable to parse '14,644' with style None.
//       Converted '14,644' to 14644.
//       Converted '14,644.00' to 14644.
//       '14,644.001' is out of range of the Int16 type.
//       Converted '145E02' to 14500.
//       Converted '145E+02' to 14500.
//       '145E-02' is out of range of the Int16 type.
open System
open System.Globalization

let parseToInt16 (value: string) (style: NumberStyles) =
    try
        let number = Int16.Parse(value, style)
        printfn $"Converted '{value}' to {number}."
    with
    | :? FormatException ->
        printfn $"Unable to parse '{value}' with style {style}."
    | :? OverflowException ->
        printfn $"'{value}' is out of range of the Int16 type."

[<EntryPoint>]
let main _ =
    // Parse a number with a thousands separator (throws an exception).
    let value = "14,644"
    let style = NumberStyles.None
    parseToInt16 value style

    let style = NumberStyles.AllowThousands
    parseToInt16 value style

    // Parse a number with a thousands separator and decimal point.
    let value = "14,644.00"
    let style = NumberStyles.AllowThousands ||| NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint
    parseToInt16 value style

    // Parse a number with a fractional component (throws an exception).
    let value = "14,644.001"
    parseToInt16 value style

    // Parse a number in exponential notation.
    let value = "145E02"
    let style = style ||| NumberStyles.AllowExponent
    parseToInt16 value style

    // Parse a number in exponential notation with a positive sign.
    let value = "145E+02"
    parseToInt16 value style

    // Parse a number in exponential notation with a negative sign
    // (throws an exception).
    let value = "145E-02"
    parseToInt16 value style

    0

// The example displays the following output to the console:
//       Unable to parse '14,644' with style None.
//       Converted '14,644' to 14644.
//       Converted '14,644.00' to 14644.
//       '14,644.001' is out of range of the Int16 type.
//       Converted '145E02' to 14500.
//       Converted '145E+02' to 14500.
//       '145E-02' is out of range of the Int16 type.
Imports System.Globalization

Module ParseSample
   Public Sub Main()
      Dim value As String 
      Dim style As NumberStyles
      
      ' Parse a number with a thousands separator (throws an exception).
      value = "14,644"
      style = NumberStyles.None
      ParseToInt16(value, style)
      
      style = NumberStyles.AllowThousands
      ParseToInt16(value, style)
      
      ' Parse a number with a thousands separator and decimal point.
      value = "14,644.00"
      style = NumberStyles.AllowThousands Or NumberStyles.Integer Or _
              NumberStyles.AllowDecimalPoint
      ParseToInt16(value, style)
      
      ' Parse a number with a fractional component (throws an exception).
      value = "14,644.001"
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation.
      value = "145E02"
      style = style Or NumberStyles.AllowExponent
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation with a positive sign.
      value = "145E+02"
      ParseToInt16(value, style)
      
      ' Parse a number in exponential notation with a negative sign
      ' (throws an exception).
      value = "145E-02"
      ParseToInt16(value, style)
   End Sub
   
   Private Sub ParseToInt16(value As String, style As NumberStyles)
      Try
         Dim number As Short = Int16.Parse(value, style)
         Console.WriteLine("Converted '{0}' to {1}.", value, number)
      Catch e As FormatException
         Console.WriteLine("Unable to parse '{0}' with style {1}.", value, _
                           style.ToString())
      Catch e As OverflowException
         Console.WriteLine("'{0}' is out of range of the Int16 type.", value)
      End Try
   End Sub   
End Module
' The example displays the following output to the console:
'       Unable to parse '14,644' with style None.
'       Converted '14,644' to 14644.
'       Converted '14,644.00' to 14644.
'       '14,644.001' is out of range of the Int16 type.
'       Converted '145E02' to 14500.
'       Converted '145E+02' to 14500.
'       '145E-02' is out of range of the Int16 type.

Açıklamalar

parametresi, style ayrıştırma işleminin başarılı olması için parametresinde s izin verilen stil öğelerini (boşluk veya işaret simgesi gibi) tanımlar. Numaralandırmadaki NumberStyles bit bayraklarının bir bileşimi olmalıdır. değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:

[ws] [$] [sign] [rakamlar,]rakamlar[.fractional_digits][e[sign]digits][ws]

Veya şunu style içeriyorsa AllowHexSpecifier:

[ws]hexdigits[ws]

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

Öğe Açıklama
Ws İsteğe bağlı boşluk. Boşluk, bayrağı içeriyorsa başında s veya bayrağı içeriyorsa sonunda NumberStyles.AllowTrailingWhitesstyle görüntülenebilir.styleNumberStyles.AllowLeadingWhite
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyPositivePattern ve NumberFormatInfo.CurrencyNegativePattern özellikleri tarafından tanımlanır. Bayrağı içeriyorsa geçerli kültürün s para birimi simgesi içinde styleNumberStyles.AllowCurrencySymbol görüntülenebilir.
imza İsteğe bağlı bir işaret. İşaret, bayrağın eklenip eklenmediğinin başında ve bayrağın eklenip eklenmediğinin styleNumberStyles.AllowTrailingSigns sonunda görünebilir.sstyleNumberStyles.AllowLeadingSign Parantezler, bayrağı içeriyorsa s negatif bir değeri style belirtmek için içinde kullanılabilirNumberStyles.AllowParentheses.
Basamak 0 ile 9 arasında bir basamak dizisi.
, Kültüre özgü binlik ayırıcı simgesi. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowThousands binlik ayırıcı simgesi içinde görüntülenebilir.styles
. Kültüre özgü ondalık nokta simgesi. Bayrağı içeriyorsa geçerli kültürün s ondalık noktası simgesi içinde styleNumberStyles.AllowDecimalPoint görüntülenebilir.
fractional_digits 0 basamaklı bir dizi. Bayrağı içeriyorsa NumberStyles.AllowDecimalPoint kesirli basamaklar içinde sstyle görüntülenebilir. fractional_digits'de 0 dışında bir basamak görünürse, yöntemi bir OverflowExceptionoluşturur.
e Üstel gösterimde temsil edilebileceğini gösteren s 'e' veya 'E' karakteri. parametresi, s bayrağını içeriyorsa üstel gösterimde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. Ancak parametresi, s veri türü aralığındaki Int16 bir sayıyı temsil etmelidir ve sıfır olmayan kesirli bileşene sahip olamaz.
hexdigits 0'dan f'ye veya 0'dan F'ye kadar 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) her zaman başarıyla ayrıştırılıyor. Kalan NumberStyles üyelerin çoğu, bu giriş dizesinde mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tablo, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediğini gösterir.

Bileşik olmayan NumberStyles değerleri Basamaklara ek olarak s içinde izin verilen öğeler
NumberStyles.None Yalnızca ondalık basamaklar.
NumberStyles.AllowDecimalPoint . ve fractional_digits öğeleri. Ancak , fractional_digits yalnızca bir veya daha fazla 0 basamak içermelidir veya bir OverflowException oluşturulur.
NumberStyles.AllowExponent parametresi üstel s gösterim de kullanabilir.
NumberStyles.AllowLeadingWhite başındaki sws öğesi.
NumberStyles.AllowTrailingWhite sonundaki s öğesi.
NumberStyles.AllowLeadingSign Basamakların önünde bir işaret görünebilir.
NumberStyles.AllowTrailingSign Basamakların ardından bir işaret görünebilir.
NumberStyles.AllowParentheses Sayısal değeri kapsayan parantez biçimindeki sign öğesi.
NumberStyles.AllowThousands öğesi.
NumberStyles.AllowCurrencySymbol $ öğesi.

NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s ön ek olmadan onaltılık değerin dize gösterimi olmalıdır. Örneğin, "9AF3" başarıyla ayrıştırıyor, ancak "0x9AF3" ayrıştırmıyor. içinde style bulunabilecek diğer bayraklar yalnızca ve NumberStyles.AllowLeadingWhite'tirNumberStyles.AllowTrailingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik bir sayı stiline NumberStyles.HexNumbersahiptir.)

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. Daha fazla bilgi için bkz. NumberFormatInfo.CurrentInfo. Belirli bir kültürün biçimlendirme bilgilerini kullanarak ayrıştırmak s için yöntemini çağırın Int16.Parse(String, NumberStyles, IFormatProvider) .

Ayrıca bkz.

Şunlara uygulanır