Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.FormatException: odniesienie praktyczne

System.FormatException: odniesienie praktyczne: FormatException oznacza tekst niezgodny z oczekiwaną składnią.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.FormatException /* select a documented member or constructor */

FormatException oznacza tekst niezgodny z oczekiwaną składnią.

Stosuj TryParse dla przewidywalnego wejścia użytkownika, a wyjątek dla naruszenia kontraktu.

Kultura i NumberStyles są częścią formatu; ten sam tekst może znaczyć co innego.

Pusty lub biały tekst zwykle nie parsuje się; przepełnienie daje OverflowException, nie FormatException.

Kompletny program rzeczywiście używa System.FormatException; oczekiwany stdout to dokładnie FormatException.

Przykłady

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); }

Wynik

FormatException

Kompletny program rzeczywiście używa `System.FormatException`; oczekiwany stdout to dokładnie `FormatException`.

Źródła