C# Convert Methods

About This Index
This page is the C# Convert Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs.
Learn what Convert is for on /c-sharp/convert. Use this page when you need a specific API such as ToInt32(), ToString(), or ToBase64String().
Convert.ToInt32(null) returns 0 for many numeric overloads. int.Parse(null) throws. Bad text still throws FormatException; out-of-range values throw OverflowException. Prefer TryParse when input may be wrong.
How to Call a Convert Method
All of these helpers are static on Convert:
int n = Convert.ToInt32("42");
string s = Convert.ToString(3.14);
bool ok = Convert.ToBoolean("True");
string b64 = Convert.ToBase64String(new byte[] { 1, 2, 3 }); C# Convert Methods Table
All method guides in this C# tutorial series (29 tutorials), grouped by purpose.
Type conversion
18 methodsConvert values between common CLR types—numbers, bool, char, DateTime, string—plus ChangeType, GetTypeCode, and IsDBNull.
| Method | Description | Tutorial |
|---|---|---|
ToBoolean() | Convert a value to bool—True/False text (case-insensitive) or non-zero numbers. | Try it |
ToByte() | Convert a value to byte (0–255). Overflow and bad format throw. | Try it |
ToSByte() | Convert a value to sbyte (−128…127). | Try it |
ToChar() | Convert a value to a single Unicode char. | Try it |
ToInt16() | Convert a value to short (Int16, −32768…32767). | Try it |
ToInt32() | Convert a value to int (Int32)—the most common Convert call. | Try it |
ToInt64() | Convert a value to long (Int64) for larger whole numbers. | Try it |
ToUInt16() | Convert a value to ushort (0…65535). | Try it |
ToUInt32() | Convert a value to uint (0…4294967295). | Try it |
ToUInt64() | Convert a value to ulong for the largest unsigned whole numbers. | Try it |
ToSingle() | Convert a value to float (Single)—32-bit floating point. | Try it |
ToDouble() | Convert a value to double—64-bit floating-point numbers. | Try it |
ToDecimal() | Convert a value to decimal—precise base-10 numbers for money and totals. | Try it |
ToDateTime() | Convert a string or object to DateTime using culture rules. | Try it |
ToString() | Convert a value to its string representation. | Try it |
ChangeType() | Convert an IConvertible value to a Type or TypeCode at runtime. | Try it |
GetTypeCode() | Return the TypeCode for a value or Type. | Try it |
IsDBNull() | Test whether a value is database null (DBNull). | Try it |
Base64
7 methodsEncode bytes as Base64 text, decode Base64 back to bytes, and Try* helpers that avoid throwing on bad input.
| Method | Description | Tutorial |
|---|---|---|
ToBase64String() | Encode a byte array as a Base64 string. | Try it |
ToBase64CharArray() | Encode bytes into a Base64 char[] buffer you provide. | Try it |
FromBase64String() | Decode a Base64 string back into a byte array. | Try it |
FromBase64CharArray() | Decode Base64 characters from a char[] slice into bytes. | Try it |
TryToBase64Chars() | Try to encode bytes into a Base64 char span without throwing on small buffers. | Try it |
TryFromBase64String() | Try to decode a Base64 string without throwing on bad input. | Try it |
TryFromBase64Chars() | Try to decode Base64 characters from a span without throwing. | Try it |
Hex
4 methodsEncode and decode hexadecimal strings (.NET 5+ ToHexString/FromHexString; newer Try* overloads).
| Method | Description | Tutorial |
|---|---|---|
ToHexString() | Encode bytes as a hexadecimal string (.NET 5+). | Try it |
FromHexString() | Decode a hex string into a byte array (.NET 5+). | Try it |
TryToHexString() | Try to write hex characters into a destination span. | Try it |
TryFromHexString() | Try to decode hex text into a byte span without throwing. | Try it |
Frequently Asked Questions
Start with ToInt32()
Turn text into a 32-bit integer—the Convert call beginners use most often.
12 people found this page helpful
