Loading...

C# Booleans

bool ripe = true; stores the word true, and Console.WriteLine(ripe) writes true. The screen is one line. There are no quotes around true, and there is no digit on that line. Keep the public class named Pine. You are not installing the SDK again.

The word you write is true or false

Open the Pine file. The class name stays Pine. This page does not rename the type. Delete int count if that line is still there, including 40, -4, and any division lines. Delete string plant if it is still there. Delete plant.Length and every line that asks a question after a dot. Delete any ReadLine line. The file you keep has no wait, no plant, no count, and no digit. The word is written only by the writing line that uses the name.

Inside Main, the storing line is bool ripe = true;. bool is the kind word. It says this name holds one of two words, true or false, and nothing else. ripe is the name, and it starts with a small r. The = sign stores the word. The word is true, every letter small: t, r, u, e. There is no capital T. There are no quotes around true. There is no digit. The semicolon ends the line. This line stores the word. It does not write the screen. Storing is not writing. The screen stays blank through this line. true is not a short way to write the number 1. false is not a short way to write 0. Those digits were the previous page. This page does not store them.

The two words are the whole of this kind. You do not invent a third word. bool ripe = yes; treats yes as a name. This file does not have a name yes. The build writes an error. bool ripe = no; does the same. The words you are allowed to write, with this kind word and with no quotes, are true and false. The file you keep uses true.

The writing line is the bare name: Console.WriteLine(ripe);. No quotes, and no dot. C# reads the name ripe, writes the word that name holds, and ends the line. For the file you keep, that word is true. The letters of the name are not on the screen. bool is not on the screen. Console 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, ripe. One word, true, all small letters, no quotes, no digit. One writing line, and that line uses the bare name.

the file you keep

csharp
using System;

public class Pine
{
    public static void Main()
    {
        bool ripe = true;
        Console.WriteLine(ripe);
    }
}

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, and there is no int line. bool ripe = true; stores the word. It writes nothing. Console.WriteLine(ripe); writes true and ends the line. One line on the screen. No quotes. No second line.

Run it with dotnet run. The program writes true. It does not wait for you to type. The word was already in the file. If dotnet run waits, ReadLine is still in the file. Delete that line and keep bool ripe = true; and the one writing line. The screen shows true. One line. No quotes. If the screen shows ripe, the writing line has quotes around the name. If the screen shows 40, or 4, or -4, or 3, the numbers file is still in place. Delete the int line. The file you keep has no digit. 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 kind. Console.WriteLine("true"); with no bool line at all would also write true, because the quotes hold the letters t, r, u, e. The screen can look the same. The file does not. The file you keep has bool, and it has true with no quotes. When you judge this page, look for the kind word and look for the absence of quotes. Do not judge the kind from the screen alone.

true, false, and what fails

Keep the allowed words and the mismatches easy to tell apart.

📊 Boolean habits for ripe

Line Fits bool Screen or result
bool ripe = true; yes true
bool ripe = false; yes false
bool ripe = "true"; no build writes an error
bool ripe = 1; no build writes an error

The other word is false

false is the other word this kind holds. It is not a second kind. The kind word stays bool. The name can stay ripe. Only the stored word changes. bool ripe = false; stores false, every letter small: f, a, l, s, e. No quotes. No digit. The writing line is still Console.WriteLine(ripe);. The screen shows false. One line. The name ripe is not on the screen. This is not a letter count, and it is not the number 0.

This is the second file. It is not the file you keep. The file you keep stores true, and its screen is true. Use this second shape when you want to see false, then put bool ripe = true; back.

the other word

csharp
using System;

public class Pine
{
    public static void Main()
    {
        bool ripe = false;
        Console.WriteLine(ripe);
    }
}

Run dotnet run. The screen shows false. One line. No quotes. If the screen shows true, the storing line still says true, which is the file you keep. If the screen shows 0, an int line is still in the file. A later line can change the word without writing bool again, once ripe already exists: ripe = false;. That line only replaces the word the name holds. It is allowed. It is not required for the file you keep. After you have seen false, put the kept file back.

Quotes and digits do not fit

Quotes around the word are letters, not this kind. bool ripe = "true"; asks a bool name to hold letters. The build writes an error. It does not turn those letters into the word true. Delete the quotes so the line is bool ripe = true; again. A digit does not fit either. bool ripe = 1; makes the build write an error. true is not 1, and false is not 0. Put true back with no quotes and no digit.

This third file is the quotes mismatch. It is not the file you keep. Keep it only until the build writes the error, then put bool ripe = true; back with no quotes.

quotes around true

csharp
using System;

public class Pine
{
    public static void Main()
    {
        bool ripe = "true";
        Console.WriteLine(ripe);
    }
}

True with a capital T is not the word this kind holds. bool ripe = True; treats True as a name. This file does not have a name True. The build writes an error. The word is true, all small letters. The same mismatch is False with a capital F. Keep leftover habits from languages that capitalize those words off this page. The file you keep uses small true.

The screen is the word you stored

You can now store one of two words with no quotes and write that word. bool ripe = true; stores true. Console.WriteLine(ripe); writes true and ends the line. bool ripe = false; writes false. Quotes around the word, or a digit such as 1, make the build write an error. The next page leaves these two words. It takes a value of one kind and writes it as another kind, so a whole number can become letters on the screen in a controlled way.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
6
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 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