C# Numbers
int count = 40; stores two digits as one whole number, and Console.WriteLine(count) writes 40. The screen is one line. The 4 is not a count of letters. The 0 is not a second number sitting beside it. Keep the public class named Pine. You are not installing the SDK again.
The digits you write are one number
Open the Pine file. The class name stays Pine. This page does not rename the type. Delete string plant if that line is still there. Delete plant.Length, delete plant[0], and delete every line that asks a question after a dot. Delete any ReadLine line. The file you keep has no wait, no plant, and no Length. The digits are written only by the writing line that uses the name.
Inside Main, the storing line is int count = 40;. int is the kind word. It says this name holds a whole number. count is the name, and it starts with a small c. The = sign stores the digits. The digits are 4, then 0, with nothing between them: no space, no comma, no point, and no quotes. The semicolon ends the line. This line stores the number. It does not write the screen. Storing is not writing. The screen stays blank through this line. The two digits are one number, forty written as 40, not the word forty, and not a 4 followed later by a separate 0.
The 4 on the letter-count page was an answer. plant.Length looked at leaf and the writing line showed 4, while the letters stayed leaf. That 4 was not typed as digits on a storing line. This page leaves that question. There is no plant to count. The 4 in 40 is a digit you typed, and the 0 next to it is the other digit of the same number. If the screen shows leaf, or leaf and then 4, the old lines are still in the file. Delete them until the only stored value is 40.
The writing line is the bare name: Console.WriteLine(count);. No quotes, and no dot. C# reads the name count, writes the whole number that name holds, and ends the line. For the file you keep, that number is 40. The letters of the name are not on the screen. int is not on the screen. Console is not on the screen. The digits 4 and 0 are on the screen, as one line, 40. Save the file.
The file you keep
Keep this teaching shape. One kind word, int. One name, count. One whole number, 40, two digits, no quotes, no point, no space between the digits, and no minus mark. One writing line, and that line uses the bare name.
using System;
public class Pine
{
public static void Main()
{
int count = 40;
Console.WriteLine(count);
}
}
Read it from the top. using System; prepares short names. public class Pine names the type. public static void Main() is where the runtime starts. There is no string plant line in the file you keep. int count = 40; stores the two digits. It writes nothing. Console.WriteLine(count); writes 40 and ends the line. One line on the screen. No quotes. No second line.
Run it with dotnet run. The program writes 40. It does not wait for you to type. The digits were already in the file. If dotnet run waits, ReadLine is still in the file. Delete that line and keep int count = 40; and the one writing line. The screen shows 40. One line. No quotes. If the screen shows count, the writing line has quotes around the name. If the screen shows 4, the storing line is still int count = 4;, one digit, or the file is still the letter-count page. The file you keep has 40, two digits. You do not reinstall the .NET SDK for a screen that shows the wrong line.
A space between the digits is not one number. int count = 4 0; has a gap between 4 and 0. The build writes an error. It does not stay quiet. Delete the gap so the line is int count = 40; again. A point is still not a whole number for int. int count = 40.0; makes the build write an error. The file you keep has 40, with no point and no digit after a point. Quotes around the digits are letters, not the whole number. int count = "40"; asks an int name to hold two digit-letters. The build writes an error. Delete the quotes if the kind word is int.
A minus mark belongs to the digits
A mark written against the digits is part of that one number. The mark is the character - with no space required between it and the first digit. int count = -4; stores one whole number. There is no second number on the line. The writing line is still Console.WriteLine(count);. The screen shows -4. One line. The mark is on the screen, tight against the digit. The name count is not on the screen.
This is the second file. It is not the file you keep. The file you keep stores 40, with no minus mark, and its screen is 40. Use this second shape when you want to see the mark, then put int count = 40; back.
using System;
public class Pine
{
public static void Main()
{
int count = -4;
Console.WriteLine(count);
}
}
Run dotnet run. The screen shows -4. One line. No quotes. If the screen shows 4, the mark is missing from the storing line. If the screen shows 40, you are still on the file you keep. A space between the mark and the digit, int count = - 4;, is still that same one number. The build stays quiet, and the screen is still -4. The file you keep does not use the mark. After you have seen -4, put the kept file back.
Whole-number division drops the fraction
Two whole numbers can sit on either side of /. The line int left = 7; stores 7. The line int right = 2; stores 2. The writing line Console.WriteLine(left / right); divides those whole numbers. The answer is not 3.5. With int, the fraction is dropped. The screen shows 3. One line. The / is not on the screen. The names left and right are not on the screen.
This is the third file. It is not the file you keep. The file you keep stores 40 and writes 40. Use this third shape when you want to see the dropped fraction, then put the kept file back.
using System;
public class Pine
{
public static void Main()
{
int left = 7;
int right = 2;
Console.WriteLine(left / right);
}
}
Run dotnet run. The screen shows 3. Not 3.5. Not 7. Not 2. If the screen shows 3.5, the names are not both int, or the writing line is not using whole-number division. The file you keep does not use this division. After you have seen 3, put int count = 40; and one WriteLine(count) back.
Quotes around the digits fail for int
This fourth file puts quotes around the digits. It is not the file you keep. Keep it only until the build writes the error, then put int count = 40; back with no quotes.
using System;
public class Pine
{
public static void Main()
{
int count = "40";
Console.WriteLine(count);
}
}
The storing line and the screen
The lines and the screens sit together here. The file you keep is the first row. The other rows are checks. They are not extra files to leave saved.
📊 The storing line and the screen
| The storing line | The screen |
|---|---|
int count = 40; |
40 |
int count = -4; |
-4 |
int left = 7; and int right = 2; then left / right |
3 |
int count = "40"; |
build writes an error |
The screen is the number you stored
You can now write a whole number as digits in the file and see those digits on the screen. int count = 40; stores 40. Console.WriteLine(count); writes 40 and ends the line. The two digits are one number, not a letter count and not two lines. int count = -4; writes -4, and the mark is part of that one number. With int, 7 / 2 writes 3 and drops the fraction. Quotes around the digits make the build write an error. The next page leaves these digits. It stores a value that is only true or false, not a whole number and not a line of letters.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top