C# Comparison
bool match = 4 == 4; stores the word true, and Console.WriteLine(match) writes true. The screen is one line. The two equal marks sit between the two fours in the file, and they are not on that line. Keep the public class named Pine.
Two equal marks ask a question
Open the Pine file. The class name stays Pine. This page does not rename the type. Delete int total if that line is still there, including 4 + 9, 9 / 4, 10 % 3, and every mark that combines two numbers into one whole number. Delete string[] plants if that line is still there. Delete string plant if that line is still there. Delete int count if that line is still there. Delete bool ripe if that line is still there with a bare true or bare false and no ask mark. Delete any ReadLine line. The file you keep has no wait, no total, no plants, no plant, no count, and no bare ripe line. The word is written only by the writing line that uses the name that holds the answer to the ask.
Inside Main, the storing line is bool match = 4 == 4;. bool is the kind word. It says this name holds one of two words, true or false. match is the name, and it starts with a small m. The first = sign stores. On the right of that first = sit two whole numbers and one ask mark. The first number is 4. The ask mark is two equal marks written together with no space between them: ==. The second number is 4. There are no quotes around either 4. The semicolon ends the line. This line stores one word. It does not write the screen. Storing is not writing. The screen stays blank through this line. The ask mark does not combine 4 and 4 into a larger number. It asks whether the left number matches the right number. When they match, the word stored is true. When they do not match, the word stored is false.
One equal mark and two equal marks are not the same work. One equal mark stores a value under a name. Two equal marks ask whether two values match. bool match = 4 == 4; has both. The first = stores. The == asks. If you write only one equal mark where the ask belongs, as in bool match = 4 = 4;, the build writes an error. That line tries to store twice in a way this page does not teach. Keep two equal marks for the ask. Keep one equal mark for the store. The operators page used one mark between two numbers to make a third number, such as 4 + 9. This page uses an ask mark between two numbers that already stand on their own. The ask does not make a third whole number. It makes true or false.
The writing line is the bare name: Console.WriteLine(match);. No quotes, and no ask mark on that line. C# reads the name match, writes the word that name holds, and ends the line. For the file you keep, that word is true. The letters of the name, m, a, t, c, h, are not on the screen. bool is not on the screen. The two equal marks are not on the screen. The digit 4 is not on the screen. The word true is on the screen, as one line. Save the file.
The file you keep
Keep this teaching shape. One kind word, bool. One name, match. One storing line that writes 4, then two equal marks, then 4, with no quotes around either number. One writing line, and that line uses the bare name. There is no total line, no plants line, and no second writing line.
using System;
public class Pine
{
public static void Main()
{
bool match = 4 == 4;
Console.WriteLine(match);
}
}
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. bool match = 4 == 4; stores the word true. It writes nothing. Console.WriteLine(match); writes true and ends the line. One line on the screen. No quotes. No second line. There is no int total line in the file you keep, and there is no line that stores a combined whole number.
Run it with dotnet run. The program writes true. It does not wait for you to type. The two numbers and the ask mark were already in the file. If dotnet run waits, ReadLine is still in the file. Delete that line and keep bool match = 4 == 4; and the one writing line. The program finishes after the writing line. The screen shows true. One line. No quotes. If the screen shows match, the writing line has quotes around the name: Console.WriteLine("match");. Those quotes mark letters, so the stored word is not written. If the screen shows 13, the operators file is still in place. Delete int total and the plus mark. If the screen shows 4, a writing line may still print a whole number instead of the bool name. The file you keep writes the word held by match. If the screen shows false, the two numbers on the storing line do not match, which is the second file on this page, not the file you keep. If the screen shows 4 == 4 as letters, the writing line has quotes around those characters. You do not reinstall the .NET SDK for a screen that shows the wrong line.
A screen that shows true does not, by itself, prove the ask mark. bool match = true; also writes true. The screen can look the same. The file does not. The file you keep has 4, then ==, then 4. When you judge this page, look for the two equal marks between the two numbers. Do not judge the file from the screen alone.
Spaces around the ask mark are allowed. bool match = 4==4; with no spaces still stores true, and the build writes no error. bool match = 4 == 4; with spaces still stores true. The file you keep uses spaces around the ask mark, because the mark is easier to see that way. The spaces are not a second value. A space between the two equal marks is not allowed. bool match = 4 = = 4; makes the build write an error. Keep the two equal marks together as ==.
The name has to exist before a line uses it. If Console.WriteLine(match); is written above bool match = 4 == 4;, the build writes an error. Move the storing line above the writing line. Do not write bool a second time for the same name. A later line can replace the word without writing bool again, once match already exists: match = 4 == 4;. That form is allowed. It is not required. The file you keep creates the name and stores the answer on one line.
When the numbers do not match
Change only the second number. Keep the kind word bool. Keep the name match. Keep the ask mark as two equal marks. bool match = 4 == 9; asks whether 4 matches 9. They do not match. The word stored is false. The writing line is still Console.WriteLine(match);. The screen shows false. One line. The name match is not on the screen. The digits 4 and 9 are not on the screen. The ask mark is not on the screen.
using System;
public class Pine
{
public static void Main()
{
bool match = 4 == 9;
Console.WriteLine(match);
}
}
This is the second file. It is not the file you keep. Run dotnet run. The screen shows false. One line. It does not show 4. It does not show 9. It does not show 4 == 9 as letters. If the screen shows true, you are still on the file you keep, where both numbers are 4. Put this second file in place only when you want to see false from an ask that does not match. After you have seen false, put the kept file back: bool match = 4 == 4; and one Console.WriteLine(match);. The kept screen is true, one line.
The ask mark does not fix the numbers. It does not change 9 into 4. It only answers. true means the two sides match. false means they do not. The booleans page stored true or false by writing the word itself. This page stores true or false by asking with a mark. Both pages use the same kind word, bool. Both pages write the same two words on the screen. The file shape is different. The file you keep on this page has the ask mark and two whole numbers.
Other ask marks
Two equal marks are not the only ask mark. A mark that asks whether the numbers are not the same is written as an exclamation mark and an equal mark together: !=. bool match = 4 != 9; stores true, because 4 and 9 are not the same. bool match = 4 != 4; stores false, because the numbers are the same. This run is allowed, and it is not the file you keep. Run dotnet run. For 4 != 9, the screen shows true. After you have seen that line, put the kept file back.
A mark that asks whether the left number is larger is written as >. bool match = 9 > 4; stores true. bool match = 4 > 9; stores false. bool match = 4 > 4; stores false, because 4 is not larger than 4. A mark that asks whether the left number is smaller is written as <. bool match = 4 < 9; stores true. bool match = 9 < 4; stores false. bool match = 4 < 4; stores false.
A mark that asks whether the left number is larger or the same is written as >=. The equal mark sits against the larger mark with no space. bool match = 4 >= 4; stores true. bool match = 9 >= 4; stores true. bool match = 4 >= 9; stores false. A mark that asks whether the left number is smaller or the same is written as <=. bool match = 4 <= 4; stores true. bool match = 4 <= 9; stores true. bool match = 9 <= 4; stores false. The extra equal mark means "or the same." It is not a second separate ask. Do not put a space inside >= or inside <=. bool match = 4 > = 4; makes the build write an error.
📊 The ask mark and the screen
| The storing line | The screen |
|---|---|
bool match = 4 == 4; |
true |
bool match = 4 == 9; |
false |
bool match = 4 != 9; |
true |
bool match = 9 > 4; |
true |
bool match = 4 < 9; |
true |
bool match = 4 >= 4; |
true |
bool match = 4 <= 9; |
true |
Read the table against a run, not instead of one. For the kept ask, the build writes no error and dotnet run writes true. For numbers that do not match with ==, the screen is false. For != with 4 and 9, the screen is true. For 9 > 4, the screen is true. For 4 < 9, the screen is true. For 4 >= 4, the screen is true. For 4 <= 9, the screen is true. After each check, put the kept file back: bool match = 4 == 4; and Console.WriteLine(match);. The kept screen is true, one line.
Quotes around a number turn it into letters. bool match = "4" == 4; asks C# to compare letters with a whole number in a way this page does not teach. The build writes an error. Delete the quotes. Both sides of the ask mark, on this page, are whole numbers with no quotes. Console.WriteLine(4 == 4); with no match name at all also writes true. The screen can look the same. The file you keep stores the answer under a name first, then writes that name. When you judge this page, look for bool match and look for the ask mark on the storing line.
This page compares whole numbers. It does not compare letters under quotes with == as the lesson you keep. A later page teaches a different way to ask whether two groups of letters match. If the screen shows leaf, or mint, plants or plant is still in the file. Delete those lines. If the screen shows 13, total is still in the file. Delete that line. Logical marks that combine two true or false answers, such as &&, belong on the next page. This page stores one ask and one answer.
Writing the ask mark as letters does not ask. Console.WriteLine("4 == 4"); writes the characters 4, space, =, =, space, 4. The screen shows 4 == 4. That is not the word true. The build stays quiet. The quotes are what stop the mark from working as an ask. The file you keep has no quotes around the numbers, and the writing line has no quotes around the name.
You can now store true or false by asking whether two whole numbers match, and write that word. bool match = 4 == 4; stores true. Console.WriteLine(match); writes true and ends the line. bool match = 4 == 9; writes false. One equal mark stores. Two equal marks ask. Other ask marks write true or false for larger, smaller, or not the same. The next page leaves a single ask. It looks at marks that combine two true or false answers into one answer.
The screen is true or false
The file you keep writes true. The name on the writing line is match, and match is not on the screen. The two equal marks are in the file, and they are not on the screen. 4 and 4 are in the file, and they are not on the screen as digits. Numbers that do not match, and the other ask marks, are not the file you keep. Quotes around the ask write letters, not the answer word.
🧠 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