Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Choosing the right data type for a value

Every value in a C# program has a type. The type decides what the value can hold and what you can do with it.

The types you will use daily

The everyday C# types
TypeHoldsExample
intWhole numbers42
doubleNumbers with a decimal part3.14
boolTrue or falsetrue
charA single character'A'
stringText of any length"hello"
DateTimeA date and timea moment

How to choose

Ask what the value represents, not what it looks like. An age is a whole number, so use int. A price is money, so consider a decimal type rather than a double. A name is text, so use string. Choosing by meaning keeps you out of trouble later.

Declare with intent. Name the variable for what it holds. A variable called count is clear. A variable called x is a future mystery.

Try it yourself in the data types lab, then continue to blocks of code and the semicolon.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.