C# Tutorial: Data Types
Integers, floats, booleans, chars, and type conversions in C#.
C# primitive types
C# has a rich set of value types. Choosing the right one matters for correctness, memory, and precision.
`decimal` is the type to use for money — it avoids floating-point rounding errors.
What you'll learn in this C# data types tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 15 minutes.
- Integer types — C# has several integer sizes. `int` (32-bit) is the default.
- Floating-point types — `double` (64-bit) is the default. `float` (32-bit) needs an `f` suffix. `decimal` is for exact decimal arithmetic.
- Boolean type — `bool` is `true` or `false`. Comparison and logical operators produce booleans.
- char type — `char` stores a single Unicode character in single quotes.
- Explicit casting — C# requires explicit casts for narrowing conversions (e.g., double to int).
- Implicit conversions — Widening conversions (small -> large) are automatic.
- Convert class — `Convert` provides safe conversions with clear naming.
- TryParse for safe input — `TryParse` returns false instead of throwing an exception on invalid input.
C# Data Types concepts covered
- C# primitive types