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

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

Lab: practise the data types

Reading about types is not the same as using them. This lab puts each one into a page and prints it.

The task

Create a page, declare one variable of each common type, and write their values into a label. Build it, run it, then change a value and run it again.

C#
int lessonCount = 7;
double rating = 4.5;
bool isFinished = false;
string learnerName = "Sam";

resultLabel.Text =
    learnerName + " has " + lessonCount + " lessons";

What to notice

  • A whole number and a decimal number are different types.
  • A boolean holds only two possible values.
  • Joining a number to text converts it for display.
Then break it on purpose. Put a word where a number is expected and read the compiler message. Understanding that message now will save you later.

Carry on with the second half of this lab.

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.