CKTIS / C#
System.Convert: praktická reference
System.Convert: praktická reference: Convert provádí definované převody mezi typy a reprezentacemi, často přes IConvertible.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Convert /* select a documented member or constructor */Convert provádí definované převody mezi typy a reprezentacemi, často přes IConvertible.
Použijte jej pro explicitní převod, když kontrakt zvoleného přetížení odpovídá zdrojovým datům.
FormatException, InvalidCastException a OverflowException hlásí různé chyby a kulturu je třeba zvolit explicitně.
Zpracování null se mezi přetíženími liší a převody s plovoucí řádovou čárkou mohou zaokrouhlovat.
Úplný program skutečně používá System.Convert; přesně očekávaný stdout je 42.
Pří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;
Console.WriteLine(Convert.ToInt32("42", CultureInfo.InvariantCulture));
Výsledek
42
Úplný program skutečně používá `System.Convert`; přesně očekávaný stdout je `42`.