FormatException Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bağımsız değişkenin biçimi geçersiz olduğunda veya bileşik biçim dizesi iyi biçimlendirilmediğinde oluşturulan özel durum.
public ref class FormatException : Exception
public ref class FormatException : SystemException
public class FormatException : Exception
public class FormatException : SystemException
[System.Serializable]
public class FormatException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class FormatException : SystemException
type FormatException = class
inherit Exception
type FormatException = class
inherit SystemException
[<System.Serializable>]
type FormatException = class
inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FormatException = class
inherit SystemException
Public Class FormatException
Inherits Exception
Public Class FormatException
Inherits SystemException
- Devralma
- Devralma
- Türetilmiş
- Öznitelikler
Açıklamalar
FormatException Aşağıdaki nedenlerden biri nedeniyle özel durum oluşturulabilir:
Dizeyi başka bir veri türüne dönüştüren bir yöntem çağrısında, dize gerekli desene uymaz. Bu genellikle sınıfın Convert bazı yöntemlerini ve bazı türlerin
ParseveParseExactyöntemlerini çağırırken oluşur.Çoğu durumda, özellikle dönüştürdüğünüz dize bir kullanıcı tarafından girdiyse veya bir dosyadan okunuyorsa, bir (
try/catchF#'ta) bloğu kullanmanıztry/withve dönüştürme başarısız olursa özel durumu işlemeniz FormatException gerekir. Dönüştürme yöntemine yapılan çağrıyı, varsa birTryParseveyaTryParseExactyöntemi çağrısıyla da değiştirebilirsiniz. Ancak, önceden tanımlanmış veya sabit kodlanmış bir FormatException dizeyi ayrıştırmaya çalışırken oluşan bir özel durum program hatasını gösterir. Bu durumda, özel durumu işlemek yerine hatayı düzeltmeniz gerekir.Bir dizenin ad alanında System aşağıdaki türlere dönüştürülmesi bir FormatException özel durum oluşturabilir:
Boolean. Boolean.Parse(String) ve Convert.ToBoolean(String) yöntemleri, dizenin "True", "true", "False" veya "false" olarak dönüştürülmesini gerektirir. Diğer tüm değerler özel durum FormatException oluşturur.
DateTime ve DateTimeOffset. Tüm tarih ve saat verileri, belirli bir kültürün biçimlendirme kurallarına göre yorumlanır: geçerli kültür (veya bazı durumlarda geçerli uygulama etki alanı kültürü), sabit kültür veya belirtilen bir kültür. ve DateTime.ParseExact(String, String, IFormatProvider, DateTimeStyles) yöntemlerini çağırdığınızda, tarih ve saat verilerinin DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles) de yöntem çağrısında bağımsız değişken olarak sağlanan bir veya daha fazla standart biçim dizesi veya özel biçim dizeleri tarafından belirtilen bir desene tam olarak uyması gerekir. Beklenen kültüre özgü bir desene uymuyorsa bir FormatException özel durum oluşturulur. Bu, bir sistemdeki kültüre özgü biçimde kaydedilen tarih ve saat verilerinin başka bir sistemde başarıyla ayrıştırılmayabileceği anlamına gelir.
Tarihleri ve saatleri ayrıştırma hakkında daha fazla bilgi için bkz. Tarih ve Saat Dizelerini Ayrıştırma ve özel durum oluşturan yöntemin belgeleri.
GUID'ler GUID'nin dize gösterimi 32 onaltılık basamak (0-F) içermelidir ve yöntemi tarafından Guid.ToString çıkış olarak beş biçimden birinde olmalıdır. Daha fazla bilgi için bkz. Guid.Parse yöntemi.
Tüm imzalı tamsayılar, işaretsiz tamsayılar ve kayan nokta türleri dahil olmak üzere sayısal türler. Ayrıştırılacak dize 0-9 Latin basamaklarından oluşmalıdır. Pozitif veya negatif işaretine, ondalık ayırıcısına, grup ayırıcılarına ve para birimi simgesine de izin verilebilir. Başka bir karakter içeren bir dizeyi ayrıştırmaya çalışmak her zaman bir FormatException özel durum oluşturur.
Tüm sayısal dizeler, belirli bir kültürün biçimlendirme kurallarına göre yorumlanır: geçerli kültür, sabit kültür veya belirtilen bir kültür. Sonuç olarak, bir kültürün kuralları kullanılarak ayrıştırılan sayısal bir dize, başka bir kültürün kuralları kullanılırken başarısız olabilir.
Sayısal dizeleri ayrıştırma hakkında daha fazla bilgi için bkz. Sayısal Dizeleri Ayrıştırma ve özel durum oluşturan belirli yöntemin belgeleri.
Zaman aralıkları. Ayrıştırılacak dize sabit kültüre duyarsız biçimde veya geçerli kültür, sabit kültür veya belirtilen bir kültür tarafından tanımlanan kültüre duyarlı bir biçimde olmalıdır. Dize uygun bir biçimde değilse veya en azından zaman aralığının gün, saat ve dakika bileşenleri yoksa, ayrıştırma yöntemi bir FormatException özel durum oluşturur. Daha fazla bilgi için TimeSpan özel durum oluşturan ayrıştırma yönteminin belgelerine bakın.
Bir tür, bir nesnenin dize gösterimine IFormattable nasıl dönüştürüldüğünü tanımlayan biçim dizelerini destekleyen arabirimini uygular ve geçersiz bir biçim dizesi kullanılır. Bu, biçimlendirme işleminde en yaygın olanıdır. Aşağıdaki örnekte, "Q" standart biçim dizesi, bir sayıyı biçimlendirmek için bileşik biçim dizesinde kullanılır. Ancak, "Q" geçerli bir standart biçim dizesi değildir.
using System; public class Example { public static void Main() { decimal price = 169.32m; Console.WriteLine("The cost is {0:Q2}.", price); } } // The example displays the following output: // Unhandled Exception: System.FormatException: Format specifier was invalid. // at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info) // at System.Decimal.ToString(String format, IFormatProvider provider) // at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) // at System.IO.TextWriter.WriteLine(String format, Object arg0) // at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) // at Example.Main()let price = 169.32m printfn $"The cost is {price:Q2}." // The example displays the following output: // Unhandled Exception: System.FormatException: Format specifier was invalid. // at System.Number.NumberToString(ValueStringBuilder& sb, NumberBuffer& number, Char format, Int32 nMaxDigits, NumberFormatInfo info) // at System.Number.TryFormatDecimal(Decimal value, ReadOnlySpan`1 format, NumberFormatInfo info, Span`1 destination, Int32& charsWritten) // at System.Decimal.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider) // at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) // at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) // at Microsoft.FSharp.Core.PrintfImpl.InterpolandToString@917.Invoke(Object vobj) // at Microsoft.FSharp.Core.PrintfImpl.PrintfEnv`3.RunSteps(Object[] args, Type[] argTys, Step[] steps) // at Microsoft.FSharp.Core.PrintfModule.gprintf[a,TState,TResidue,TResult,TPrinter](FSharpFunc`2 envf, PrintfFormat`4 format) // at <StartupCode$fs>.$Example.main@()Module Example Public Sub Main() Dim price As Decimal = 169.32d Console.WriteLine("The cost is {0:Q2}.", price) End Sub End Module ' The example displays the following output: ' Unhandled Exception: System.FormatException: Format specifier was invalid. ' at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info) ' at System.Decimal.ToString(String format, IFormatProvider provider) ' at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) ' at System.IO.TextWriter.WriteLine(String format, Object arg0) ' at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) ' at Example.Main()Bu özel durum bir kodlama hatasından kaynaklanır. Hatayı düzeltmek için biçim dizesini kaldırın veya geçerli bir dizeyi kullanın. Aşağıdaki örnek, geçersiz biçim dizesini "C" (para birimi) biçim dizesiyle değiştirerek hatayı düzeltir.
using System; public class Example { public static void Main() { decimal price = 169.32m; Console.WriteLine("The cost is {0:C2}.", price); } } // The example displays the following output: // The cost is $169.32.let price = 169.32m printfn $"The cost is {price:C2}." // The example displays the following output: // The cost is $169.32.Module Example Public Sub Main() Dim price As Decimal = 169.32d Console.WriteLine("The cost is {0:C2}.", price) End Sub End Module ' The example displays the following output: ' The cost is $169.32.Ayrıca FormatException ve gibi, dizenin bir biçim dizesi tarafından belirtilen desene tam olarak DateTime.ParseExactGuid.ParseExactuyması için ayrıştırılması gereken ayrıştırma yöntemleri tarafından özel durum oluşturulabilir. Aşağıdaki örnekte, bir GUID'nin dize gösteriminin "G" standart biçim dizesi tarafından belirtilen desene uyması beklenmektedir. Ancak yapısının Guid uygulaması IFormattable "G" biçim dizesini desteklemez.
using System; public class Example { public static void Main() { string guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"; Console.WriteLine(Guid.ParseExact(guidString, "G")); } } // The example displays the following output: // Unhandled Exception: System.FormatException: // Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x". // at System.Guid.ParseExact(String input, String format) // at Example.Main()open System let guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb" printfn $"""{Guid.ParseExact(guidString, "G")}""" // The example displays the following output: // Unhandled Exception: System.FormatException: // Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x". // at System.Guid.ParseExact(String input, String format) // at <StartupCode$fs>.$Example.main@()Module Example Public Sub Main() Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb" Console.WriteLine(Guid.ParseExact(guidString, "G")) End Sub End Module ' The example displays the following output: ' Unhandled Exception: System.FormatException: ' Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x". ' at System.Guid.ParseExact(String input, String format) ' at Example.Main()Bu özel durum ayrıca bir kodlama hatasından da kaynaklanır. Düzeltmek için, veya DateTime.Parsegibi Guid.Parse kesin bir biçim gerektirmeyen bir ayrıştırma yöntemini çağırarak veya geçerli bir biçim dizesini kullanın. Aşağıdaki örnek, yöntemini çağırarak hatayı düzeltmektedir Guid.Parse .
using System; public class Example { public static void Main() { string guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"; Console.WriteLine(Guid.Parse(guidString)); } } // The example displays the following output: // ba748d5c-ae5f-4cca-84e5-1ac5291c38cbopen System let guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb" printfn $"{Guid.Parse guidString}" // The example displays the following output: // ba748d5c-ae5f-4cca-84e5-1ac5291c38cbModule Example Public Sub Main() Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb" Console.WriteLine(Guid.Parse(guidString)) End Sub End Module ' The example displays the following output: ' ba748d5c-ae5f-4cca-84e5-1ac5291c38cbBileşik biçim dizesindeki biçim öğelerinin dizinlerinden biri veya daha fazlası nesne listesindeki veya parametre dizisindeki öğelerin dizinlerinden büyüktür. Aşağıdaki örnekte, biçim dizesindeki bir biçim öğesinin en büyük dizini 3'tür. Nesne listesindeki öğelerin dizinleri sıfır tabanlı olduğundan, bu biçim dizesi nesne listesinin dört öğeye sahip olmasını gerektirir. Bunun yerine yalnızca üç
dat,tempvescaleöğesine sahiptir, bu nedenle kod çalışma zamanında bir FormatException özel durumla sonuçılır:using System; public class Example { public enum TemperatureScale { Celsius, Fahrenheit, Kelvin } public static void Main() { String info = GetCurrentTemperature(); Console.WriteLine(info); } private static String GetCurrentTemperature() { DateTime dat = DateTime.Now; Decimal temp = 20.6m; TemperatureScale scale = TemperatureScale.Celsius; String result; result = String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}", dat, temp, scale); return result; } } // The example displays output like the following: // Unhandled Exception: System.FormatException: Format specifier was invalid. // at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info) // at System.Decimal.ToString(String format, IFormatProvider provider) // at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) // at System.String.Format(IFormatProvider provider, String format, Object[] args) // at Example.Main()open System type TemperatureScale = | Celsius = 0 | Fahrenheit = 1 | Kelvin = 2 let getCurrentTemperature () = let dat = DateTime.Now let temp = 20.6m let scale = TemperatureScale.Celsius String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}", dat, temp, scale) getCurrentTemperature () |> printfn "%s" // The example displays output like the following: // Unhandled Exception: System.FormatException: Format specifier was invalid. // at System.Number.NumberToString(ValueStringBuilder& sb, NumberBuffer& number, Char format, Int32 nMaxDigits, NumberFormatInfo info) // at System.Number.TryFormatDecimal(Decimal value, ReadOnlySpan`1 format, NumberFormatInfo info, Span`1 destination, Int32& charsWritten) // at System.Decimal.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider) // at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) // at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) // at System.String.Format(String format, Object arg0, Object arg1, Object arg2) // at Example.getCurrentTemperature() // at <StartupCode$fs>.$Example.main@()Module Example Public Enum TemperatureScale As Integer Celsius Fahrenheit Kelvin End Enum Public Sub Main() Dim info As String = GetCurrentTemperature() Console.WriteLine(info) End Sub Private Function GetCurrentTemperature() As String Dim dat As Date = Date.Now Dim temp As Decimal = 20.6d Dim scale As TemperatureScale = TemperatureScale.Celsius Dim result As String result = String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}", dat, temp, scale) Return result End Function End Module ' The example displays output like the following: ' Unhandled Exception: System.FormatException: Format specifier was invalid. ' at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info) ' at System.Decimal.ToString(String format, IFormatProvider provider) ' at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) ' at System.String.Format(IFormatProvider provider, String format, Object[] args) ' at Example.Main()Bu durumda, FormatException özel durum geliştirici hatasının bir sonucudur. Nesne listesindeki her öğenin bir
try/catchbiçim öğesinin dizinine karşılık gelen olduğundan emin olarak bir blokta işlenmek yerine düzeltilmelidir. Bu örneği düzeltmek için, ikinci biçim öğesinin dizinini değişkenine başvuracakdatşekilde değiştirin ve izleyen her biçim öğesinin dizinini birer birer azaltın.using System; public class Example { public enum TemperatureScale { Celsius, Fahrenheit, Kelvin } public static void Main() { String info = GetCurrentTemperature(); Console.WriteLine(info); } private static String GetCurrentTemperature() { DateTime dat = DateTime.Now; Decimal temp = 20.6m; TemperatureScale scale = TemperatureScale.Celsius; String result; result = String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}", dat, temp, scale); return result; } } // The example displays output like the following: // At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 Celsiusopen System type TemperatureScale = | Celsius = 0 | Fahrenheit = 1 | Kelvin = 2 let getCurrentTemperature () = let dat = DateTime.Now let temp = 20.6m let scale = TemperatureScale.Celsius String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}", dat, temp, scale) getCurrentTemperature () |> printfn "%s" // The example displays output like the following: // At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 CelsiusModule Example Public Enum TemperatureScale As Integer Celsius Fahrenheit Kelvin End Enum Public Sub Main() Dim info As String = GetCurrentTemperature() Console.WriteLine(info) End Sub Private Function GetCurrentTemperature() As String Dim dat As Date = Date.Now Dim temp As Decimal = 20.6d Dim scale As TemperatureScale = TemperatureScale.Celsius Dim result As String result = String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}", dat, temp, scale) Return result End Function End Module ' The example displays output like the following: ' At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 CelsiusBileşik biçim dizesi iyi biçimlendirilmemiş. Bu durumda, FormatException özel durum her zaman geliştirici hatasının bir sonucudur. Bir blokta
try/catchişlenmek yerine düzeltilmelidir.Aşağıdaki örnekte olduğu gibi bir dizeye değişmez ayraç eklemeye çalışmak özel durum oluşturur.
result = String.Format("The text has {0} '{' characters and {1} '}' characters.", nOpen, nClose);let result = String.Format("The text has {0} '{' characters and {1} '}' characters.", nOpen, nClose)result = String.Format("The text has {0} '{' characters and {1} '}' characters.", nOpen, nClose)Değişmez ayraçları bileşik biçim dizesine eklemek için önerilen teknik, bunları nesne listesine eklemek ve sonuç dizesine eklemek için biçim öğelerini kullanmaktır. Örneğin, önceki bileşik biçim dizesini burada gösterildiği gibi değiştirebilirsiniz.
string result; int nOpen = 1; int nClose = 2; result = String.Format("The text has {0} '{{' characters and {1} '}}' characters.", nOpen, nClose); Console.WriteLine(result);let result = String.Format("The text has {0} '{{' characters and {1} '}}' characters.", nOpen, nClose)result = String.Format("The text has {0} '{{' characters and {1} '}}' characters.", nOpen, nClose)Biçim dizeniz yazım hatası içeriyorsa özel durum da oluşturulur. Aşağıdaki yöntem çağrısı String.Format , bir kapanış ayracı atlar ve bir açılış ayracı kapanış ayracı ile eşleştirir.
int n1 = 10; int n2 = 20; String result = String.Format("{0 + {1] = {2}", n1, n2, n1 + n2);let n1 = 10 let n2 = 20 String result = String.Format("{0 + {1] = {2}", n1, n2, n1 + n2)Dim n1 As Integer = 10 Dim n2 As Integer = 20 Dim result As String = String.Format("{0 + {1] = {2}", n1, n2, n1 + n2)Hatayı düzeltmek için tüm açma ve kapatma küme ayraçlarının karşılık gelen olduğundan emin olun.
String result = String.Format("{0} + {1} = {2}", n1, n2, n1 + n2);let result = String.Format("{0} + {1} = {2}", n1, n2, n1 + n2)Dim result As String = String.Format("{0} + {1} = {2}", n1, n2, n1 + n2)Bileşik biçimlendirme yönteminde nesne listesini kesin olarak belirlenmiş bir parametre dizisi olarak sağladınız ve FormatException özel durum, bir veya daha fazla biçim öğesinin dizininin nesne listesindeki bağımsız değişken sayısını aştığını gösteriyor. Bunun nedeni dizi türleri arasında açık dönüştürme olmamasıdır, bu nedenle derleyici diziyi parametre dizisi yerine tek bir bağımsız değişken olarak ele alır. Örneğin, biçim öğelerinin Console.WriteLine(String, Object[]) en yüksek dizini 3 olmasına ve türdeki FormatException parametre dizisinin dört öğeye sahip olmasına rağmen, yöntemine yapılan aşağıdaki çağrı bir Int32 özel durum oluşturur.
using System; using System.Collections.Generic; public class Example { public static void Main() { Random rnd = new Random(); int[] numbers = new int[4]; int total = 0; for (int ctr = 0; ctr <= 2; ctr++) { int number = rnd.Next(1001); numbers[ctr] = number; total += number; } numbers[3] = total; Console.WriteLine("{0} + {1} + {2} = {3}", numbers); } } // The example displays the following output: // Unhandled Exception: // System.FormatException: // Index (zero based) must be greater than or equal to zero and less than the size of the argument list. // at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) // at System.IO.TextWriter.WriteLine(String format, Object arg0) // at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) // at Example.Main()open System let rnd = Random() let numbers = Array.zeroCreate<int> 4 let mutable total = 0 for i = 0 to 2 do let number = rnd.Next 1001 numbers[i] <- number total <- total + number numbers[3] <- total Console.WriteLine("{0} + {1} + {2} = {3}", numbers) // The example displays the following output: // Unhandled Exception: // System.FormatException: // Index (zero based) must be greater than or equal to zero and less than the size of the argument list. // at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) // at System.IO.TextWriter.WriteLine(String format, Object arg0) // at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) // at <StartupCode$fs>.$Example.main@()Imports System.Collections.Generic Module Example Public Sub Main() Dim rnd As New Random() Dim numbers(3) As Integer Dim total As Integer = 0 For ctr = 0 To 2 Dim number As Integer = rnd.Next(1001) numbers(ctr) = number total += number Next numbers(3) = total Console.WriteLine("{0} + {1} + {2} = {3}", numbers) End Sub End Module ' The example displays the following output: ' Unhandled Exception: ' System.FormatException: ' Index (zero based) must be greater than or equal to zero and less than the size of the argument list. ' at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) ' at System.IO.TextWriter.WriteLine(String format, Object arg0) ' at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) ' at Example.Main()Bu özel durumu işlemek yerine nedenini ortadan kaldırmanız gerekir. Ne Visual Basic ne de C# bir tamsayı dizisini nesne dizisine dönüştüremediğinden, bileşik biçimlendirme yöntemini çağırmadan önce dönüştürmeyi kendiniz gerçekleştirmeniz gerekir. Aşağıdaki örnek bir uygulama sağlar.
using System; using System.Collections.Generic; public class Example { public static void Main() { Random rnd = new Random(); int[] numbers = new int[4]; int total = 0; for (int ctr = 0; ctr <= 2; ctr++) { int number = rnd.Next(1001); numbers[ctr] = number; total += number; } numbers[3] = total; object[] values = new object[numbers.Length]; numbers.CopyTo(values, 0); Console.WriteLine("{0} + {1} + {2} = {3}", values); } } // The example displays output like the following: // 477 + 956 + 901 = 2334open System let rnd = Random() let numbers = Array.zeroCreate<int> 4 let mutable total = 0 for i = 0 to 2 do let number = rnd.Next 1001 numbers[i] <- number total <- total + number numbers[3] <- total let values = Array.zeroCreate<obj> numbers.Length numbers.CopyTo(values, 0) Console.WriteLine("{0} + {1} + {2} = {3}", values) // The example displays output like the following: // 477 + 956 + 901 = 2334Imports System.Collections.Generic Module Example Public Sub Main() Dim rnd As New Random() Dim numbers(3) As Integer Dim total As Integer = 0 For ctr = 0 To 2 Dim number As Integer = rnd.Next(1001) numbers(ctr) = number total += number Next numbers(3) = total Dim values(numbers.Length - 1) As Object numbers.CopyTo(values, 0) Console.WriteLine("{0} + {1} + {2} = {3}", values) End Sub End Module ' The example displays output like the following: ' 477 + 956 + 901 = 2334
FormatException değeri 0x80131537 olan HRESULT COR_E_FORMAT kullanır.
sınıfı FormatException öğesinden Exception türetilir ve benzersiz üye eklemez. FormatExceptionörneğinin ilk özellik değerlerinin listesi için bkz. FormatException oluşturucuları.
Oluşturucular
| Name | Description |
|---|---|
| FormatException() |
FormatException sınıfının yeni bir örneğini başlatır. |
| FormatException(SerializationInfo, StreamingContext) |
Geçersiz.
Serileştirilmiş verilerle FormatException sınıfının yeni bir örneğini başlatır. |
| FormatException(String, Exception) |
Belirtilen bir hata iletisi ve bu özel durumun nedeni olan iç özel duruma başvuru ile FormatException sınıfının yeni bir örneğini başlatır. |
| FormatException(String) |
Belirtilen bir hata iletisiyle sınıfının yeni bir örneğini FormatException başlatır. |
Özellikler
| Name | Description |
|---|---|
| Data |
Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır. (Devralındığı yer: Exception) |
| HelpLink |
Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar. (Devralındığı yer: Exception) |
| HResult |
Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar. (Devralındığı yer: Exception) |
| InnerException |
Geçerli özel duruma neden olan Exception örneğini alır. (Devralındığı yer: Exception) |
| Message |
Geçerli özel durumu açıklayan bir ileti alır. (Devralındığı yer: Exception) |
| Source |
Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar. (Devralındığı yer: Exception) |
| StackTrace |
Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır. (Devralındığı yer: Exception) |
| TargetSite |
Geçerli özel durumu oluşturan yöntemini alır. (Devralındığı yer: Exception) |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetBaseException() |
Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan Exception döndürür. (Devralındığı yer: Exception) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Geçersiz.
Türetilmiş bir sınıfta geçersiz kılındığında, özel durumla ilgili bilgilerle SerializationInfo ayarlar. (Devralındığı yer: Exception) |
| GetType() |
Geçerli örneğin çalışma zamanı türünü alır. (Devralındığı yer: Exception) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli özel durumun dize gösterimini oluşturur ve döndürür. (Devralındığı yer: Exception) |
Ekinlikler
| Name | Description |
|---|---|
| SerializeObjectState |
Geçersiz.
Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir. (Devralındığı yer: Exception) |