C# Convert

Beginner
7 min read
Updated: Nov 2026
3 examples
Convert

Definition and Usage

In C#, System.Convert is the standard way to change a value from one type to another: read numbers with ToInt32(), build text with ToString(), flip bools with ToBoolean(), and encode bytes as Base64 or hex.

Most beginner programs start with using System; and then call Convert.ToInt32("42") or Convert.ToString(99).

This page introduces Convert. The Convert Methods index lists every method guide in this series.

Null and exceptions.

For many numeric To* overloads, a null argument becomes 0. Invalid text still throws FormatException, and values that do not fit throw OverflowException.

C# Syntax

Common first calls:

C#
int n = Convert.ToInt32("42");
string s = Convert.ToString(3.14);
bool b = Convert.ToBoolean("True");
Console.WriteLine(Convert.ToInt32("42"));

Convert vs Parse

A quick map of how Convert compares to type Parse helpers:

APINull inputBad text
Convert.ToInt32Often returns 0FormatException
int.ParseThrowsFormatException
int.TryParseReturns falseReturns false (no throw)

C# Examples

Three short programs that show everyday Convert calls.

Example 1 — Parse a Number with ToInt32

A first program that converts a digit string into an int.

C#
using System;

class Program {
    static void Main() {
        int n = Convert.ToInt32("42");
        Console.WriteLine(n);
        Console.WriteLine(n + 8);
    }
}

How It Works

  1. String in. "42" is text until Convert turns it into a number.
  2. ToInt32. The call returns a 32-bit signed integer.
  3. Use as int. Adding 8 works because n is numeric, not text.

Example 2 — Turn Values into Text with ToString

Show how Convert.ToString builds display text from numbers and bools.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Convert.ToString(99));
        Console.WriteLine(Convert.ToString(true));
        Console.WriteLine(Convert.ToString(3.5));
    }
}

How It Works

  1. Any common type. Numbers and bools become culture-aware text.
  2. Bool spelling. true prints as True.
  3. Ready to print. The results are strings you can concatenate or log.

Example 3 — See Convert Null Behavior

Compare Convert.ToInt32(null) with a normal digit string.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Convert.ToInt32("10"));
        Console.WriteLine(Convert.ToInt32(null));
    }
}

How It Works

  1. Valid digits. "10" converts to integer 10.
  2. Null becomes zero. For many numeric To* overloads, null yields 0.
  3. Unlike Parse. int.Parse(null) throws—Convert is more forgiving on null.

Next: C# Convert Methods Index

After you know what Convert is for, open the method index for a full tutorial on each System.Convert API.

Start withWhy
ToInt32()Turn digit text into a 32-bit int
ToString()Build display text from common types
ToBoolean()Read True/False text or numeric flags
ToBase64String()Encode bytes as Base64 text

Full list: C# Convert Methods index (/c-sharp/convert/method).

Frequently Asked Questions

It is the standard C# API for converting values between common types—ToInt32, ToString, ToBoolean—and for Base64/hex encoding helpers.
Both read integers from strings. Convert.ToInt32(null) returns 0; int.Parse(null) throws. Use TryParse when text may be invalid.
Yes. Wrong format raises FormatException; out-of-range values raise OverflowException for many To* methods.
ToBase64String/FromBase64String and ToHexString/FromHexString (plus Try* helpers) live on Convert as well.
Open the C# Convert Methods index. It lists ToInt32, ToString, ToBoolean, Base64, hex, and the rest.

Browse every Convert method

Open the methods index for categorized guides with examples and FAQs.

Convert Methods Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful