CKTIS / C#
System.FormatException: praktische referentie
System.FormatException: praktische referentie: FormatException meldt tekst die niet voldoet aan de door parser of formatter verwachte syntaxis.
Versie: .NET API; verified on .NET 10.0.14
Syntax
System.FormatException /* select a documented member or constructor */FormatException meldt tekst die niet voldoet aan de door parser of formatter verwachte syntaxis.
Gebruik TryParse voor voorspelbare gebruikersinvoer en reserveer de uitzondering voor een geschonden programmeercontract.
Cultuur en NumberStyles horen bij het formaat, zodat dezelfde tekst iets anders kan betekenen.
Lege tekst of witruimte mislukt meestal; een getal buiten bereik werpt in plaats daarvan OverflowException.
Het volledige programma gebruikt System.FormatException werkelijk; de exact verwachte stdout is FormatException.
Voorbeelden
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); }
Resultaat
FormatException
Het volledige programma gebruikt `System.FormatException` werkelijk; de exact verwachte stdout is `FormatException`.