Int16.Parse Yöntem

Tanım

Bir sayının dize gösterimini 16 bit işaretli 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 imzalı 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 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)

Belirtilen 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)

Source:
Int16.cs
Source:
Int16.cs
Source:
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 sayıyı içeren bir 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.

provider
IFormatProvider

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

Döndürülenler

içinde belirtilen ssayıya eşdeğer 16 bit imzalı tamsayı.

Uygulamalar

Ö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.

sInt16.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;
Int16 number;
NumberStyles style;

// Parse string using "." as the thousands separator 
// and " " as the decimal separator.
value = "19 694,00";
style = NumberStyles::AllowDecimalPoint | NumberStyles::AllowThousands;
CultureInfo^ provider = gcnew 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 ^e)
{
   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 = gcnew CultureInfo("en-GB");

try
{
   number = Int16::Parse(value, style, CultureInfo::InvariantCulture);
   Console::WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '$6,032.00'.
                        
provider = gcnew CultureInfo("en-US");
number = Int16::Parse(value, style, provider);
Console::WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '$6,032.00' converted to 6032.
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 parametrede s izin verilen stil öğelerini (boşluk veya pozitif işaret 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,]digits[.fractional_digits][e[sign]digits][ws]

Veya içeriyorsa styleAllowHexSpecifier:

[ws]hexdigits[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. Bayrağı içeriyorsa başında sstyle veya bayrağı içeriyorsa NumberStyles.AllowLeadingWhite sonunda sstyleNumberStyles.AllowTrailingWhite boşluk görüntülenebilir.
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyPositivePattern ve NumberFormatInfo.CurrencyNegativePattern özelliği 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ğını 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.
Basamak 0 İle 9 arasında bir basamak dizisi.
, Kültüre özgü binler basamaklarını ayıran simge. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowThousands binlik ayırıcı simgesi içinde sstyle görünebilir.
. 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 0 basamaklı bir dizi. Bayrağı içeriyorsa NumberStyles.AllowDecimalPoint kesirli basamaklar içinde sstyle görünebilir. fractional_digits'da 0 dışında bir basamak görünürse, yöntemi bir OverflowExceptionoluşturur.
E Üstel gösterimin gösterilebileceğini gösteren s 'e' veya 'E' karakteri. parametresi, s bayrağını içeriyorsa bir sayıyı üstel gösteriminde styleNumberStyles.AllowExponent gösterebilir. Ancak parametresi, s veri türü aralığındaki Int16 bir sayıyı temsil etmelidir ve sıfır olmayan bir kesirli bileşene sahip olamaz.
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 basamakları 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 bulunması gerekmeyen öğeleri denetler. Aşağıdaki tabloda, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediği gösterilir.

Bileşik olmayan NumberStyles değerleri Basamaklara olarak s bileşeninde 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österimi de kullanabilir.
NumberStyles.AllowLeadingWhite başındaki sws öğesi.
NumberStyles.AllowTrailingWhite sonundaki sws öğesi.
NumberStyles.AllowLeadingSign Basamakların önüne 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 bulunabilecek style diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik sayı stiline NumberStyles.HexNumbersahiptir.)

provider parametresi, yöntemi bir nesnesi alan bir IFormatProviderNumberFormatInfo uygulamadırGetFormat. NumberFormatInfo nesnesi, 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)

Source:
Int16.cs
Source:
Int16.cs
Source:
Int16.cs

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

Source:
Int16.cs
Source:
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 utf8Textsonucu.

Uygulamalar

Şunlara uygulanır

Parse(String, IFormatProvider)

Source:
Int16.cs
Source:
Int16.cs
Source:
Int16.cs

Belirtilen kültüre özgü biçimdeki bir sayının dize gösterimini 16 bit işaretli 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 sayıyı içeren bir 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 değeridir.

s doğru biçimde değil.

sInt16.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;
Int16 number;

stringToConvert = " 214 ";
try
{
   number = Int16::Parse(stringToConvert, CultureInfo::InvariantCulture);
   Console::WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   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 ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   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 ^e)
{
   Console::WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException ^e)
{
   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.
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ç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ı bir boşluk.
sign İsteğe bağlı bir işaret.
rakamlar 0 İle 9 arasında değişen 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şluklara ve başındaki işarete 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 nesnesi 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)

Source:
Int16.cs
Source:
Int16.cs
Source:
Int16.cs

Bir sayının dize gösterimini 16 bit işaretli 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 sayıyı içeren bir dize.

Döndürülenler

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

Özel durumlar

s, null değeridir.

s doğru biçimde değil.

sInt16.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;
Int16 number;
   
value = " 12603 ";
try
{
   number = Int16::Parse(value);
   Console::WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException ^e)
{
   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 ^e)
{
   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 ^e)
{
   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.
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ç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.
Basamak 0 İle 9 arasında değişen 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)

Source:
Int16.cs
Source:
Int16.cs
Source:
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ı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:
Int16.cs
Source:
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 utf8Textsonucu.

Uygulamalar

Şunlara uygulanır

Parse(String, NumberStyles)

Source:
Int16.cs
Source:
Int16.cs
Source:
Int16.cs

Belirtilen stildeki bir sayının dize gösterimini 16 bit işaretli 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 sayıyı içeren bir 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 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.

sInt16.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 namespace System;
using namespace System::Globalization;

ref 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;
      ParseSample::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
      {
         Int16 number = Int16::Parse(value, style);
         Console::WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException ^e)
      {
         Console::WriteLine("Unable to parse '{0}' with style {1}.", value, 
                            style);
      }
      catch (OverflowException ^e)
      {
         Console::WriteLine("'{0}' is out of range of the Int16 type.", value);
      }
   }
};

int main()
{
    ParseSample::Main();
    Console::ReadLine();
    return 0;
}
// The example displays the following output:
//       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.
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][digits,]digits[.fractional_digits][e[sign]digits][ws]

Veya içeriyorsa styleAllowHexSpecifier:

[ws]hexdigits[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. Bayrağın eklenip eklenmediğinin sNumberStyles.AllowLeadingWhitestyle başında veya bayrağın dahil olup olmadığının sstyleNumberStyles.AllowTrailingWhite sonunda boşluk görünebilir.
$ Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyPositivePattern ve NumberFormatInfo.CurrencyNegativePattern özelliği 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ğını içeriyorsa öğesinin sstyleNumberStyles.AllowLeadingSign başında ve bayrağını içeriyorsa NumberStyles.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.
Basamak 0 İle 9 arasında bir basamak dizisi.
, Kültüre özgü binler basamaklarını ayıran simge. bayrağını style içeriyorsa geçerli kültürün NumberStyles.AllowThousands binlik ayırıcı simgesi 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.
fractional_digits 0 basamaklı bir dizi. bayrağını style içeriyorsa kesirli basamaklar NumberStyles.AllowDecimalPoint içinde s görüntülenebilir. fractional_digits'da 0 dışında bir basamak görünüyorsa, yöntemi bir OverflowExceptionoluşturur.
E Üstel gösterimin gösterilebileceğini gösteren s 'e' veya 'E' karakteri. parametresi, s bayrağını içeriyorsa üstel gösteriminde 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 bir kesirli bileşene sahip olamaz.
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) 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 olarak s bileşeninde 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österimi de kullanabilir.
NumberStyles.AllowLeadingWhite başındaki sws öğesi.
NumberStyles.AllowTrailingWhite sonundaki sws öğesi.
NumberStyles.AllowLeadingSign Rakamlardan önce 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 işaret öğesi.
NumberStyles.AllowThousands , öğesi.
NumberStyles.AllowCurrencySymbol $ öğesi.

NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s ön eki olmayan 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 bulunabilecek style diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik 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