CKTIS / C#
System.FormatException: praktická referencia
System.FormatException: praktická referencia: FormatException označuje text, ktorý nezodpovedá syntaxi očakávanej parserom alebo formátovačom.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.FormatException /* select a documented member or constructor */FormatException označuje text, ktorý nezodpovedá syntaxi očakávanej parserom alebo formátovačom.
Pre očakávaný používateľský vstup použite TryParse a výnimku ponechajte pre porušenie programového kontraktu.
Kultúra a NumberStyles sú súčasťou formátu, takže rovnaký text môže mať iný význam.
Prázdny text či medzery zvyčajne zlyhajú; číslo mimo rozsahu vyvolá namiesto toho OverflowException.
Úplný program skutočne používa System.FormatException; presne očakávaný stdout je FormatException.
Príklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
try { int.Parse("x", CultureInfo.InvariantCulture); } catch (FormatException error) { Console.WriteLine(error.GetType().Name); }
Výsledok
FormatException
Úplný program skutočne používa `System.FormatException`; presne očakávaný stdout je `FormatException`.