C# null
string plant = null; stores no letters, and Console.WriteLine(plant) writes null. The screen is one line. There are no quotes around null, and there is no digit on that line. Keep the public class named Pine.
The name holds no letters
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 (int), 40.0, 40.9, and 40. Delete double weight if it is still there. Delete bool ripe if it is still there, including true and false. 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 count, no weight, no ripe, and no parentheses. The word is written only by the writing line that uses the name.
Inside Main, the storing line is string plant = null;. string is the kind word. It says this name can hold letters, or it can hold no letters at all. plant is the name, and it starts with a small p. The = sign stores. The word is null, every letter small: n, u, l, l. There is no capital N. There are no quotes around null. There is no digit. The semicolon ends the line. This line stores no letters. It does not write the screen. Storing is not writing. The screen stays blank through this line. null is not a short way to write the number 0. null is not the word leaf with the letters missing from the screen only. Nothing is stored. The letters leaf are not waiting somewhere in this name.
On this page, this kind holds either letters between quotes, such as leaf, or the word null with no quotes. You do not invent a third word. string plant = none; treats none as a name. This file does not have a name none. The build writes an error. string plant = empty; does the same. The word you are allowed to write, with this kind word and with no quotes, is null. The file you keep uses null.
The writing line is the bare name: Console.WriteLine(plant);. No quotes, and no dot. C# reads the name plant, writes what that name holds, and ends the line. For the file you keep, the name holds no letters, so the writing line writes the word null. The letters of the name, p, l, a, n, t, are not on the screen. string is not on the screen. Console is not on the screen. The word null is on the screen, as one line. Save the file.
The file you keep
Keep this teaching shape. One kind word, string. One name, plant. One word, null, all small letters, no quotes, no digit. One writing line, and that line uses the bare name. There is no Length.
using System;
public class Pine
{
public static void Main()
{
string plant = null;
Console.WriteLine(plant);
}
}
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. The word string on a later storing line is the one that matters here. string plant = null; stores no letters. It writes nothing. Console.WriteLine(plant); writes null and ends the line. One line on the screen. No quotes. No second line. There is no int line in the file you keep.
Run it with dotnet run. The program writes null. 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 string plant = null; and the one writing line. The program finishes after the writing line. The screen shows null. One line. No quotes. If the screen shows plant, the writing line has quotes around the name: Console.WriteLine("plant");. Those quotes mark the letters p, l, a, n, t, so the stored word is not written. If the screen shows leaf, the storing line still says "leaf". Delete those quotes and the letters, and write null with no quotes. If the screen shows 40, or 40.0, or 4, the casting file or the numbers file is still in place. Delete the int line and the parentheses. If the screen shows true or false, ripe is still in the file. If the screen shows a blank line and not the word null, the storing line has quotes with nothing between them: string plant = "";. That is not the file you keep. The file you keep has the word null and no quotes. You do not reinstall the .NET SDK for a screen that shows the wrong line.
A screen that shows null does not, by itself, prove the file. string plant = "null"; with quotes around those four letters also writes null, because the quotes hold n, u, l, l. The screen can look the same. The file does not. The file you keep has string, and it has null with no quotes. When you judge this page, look for the kind word and look for the absence of quotes. Do not judge the file from the screen alone.
Quotes hold the letters null
Quotes around the word are letters, not the empty name. string plant = "null"; stores four letters. The build writes no error. dotnet run writes null. That run is allowed, and it is not the file you keep. The file you keep has no quotes, so the name holds no letters. When you are repairing the kept file, delete the quotes so the line is string plant = null; again. Do not delete the word null with them.
📊 The storing line and the screen
| The storing line | The screen |
|---|---|
string plant = null; |
null |
string plant = "null"; |
null |
string plant = "leaf"; |
leaf |
int count = null; |
the build writes an error |
Read the table against a run, not instead of one. For string plant = null;, the build writes no error and dotnet run writes null. For string plant = "null";, the build writes no error and dotnet run writes null, and the file still has quotes. For string plant = "leaf";, the build writes no error and dotnet run writes leaf. For int count = null;, the build writes an error, so you do not run. After each check, put string plant = null; back, with no quotes. The kept screen is null, one line.
The name has to exist before a line uses it. If Console.WriteLine(plant); is written above string plant = null;, the build writes an error. Move the storing line above the writing line. Do not write string a second time for the same name. string plant = "leaf"; placed under a line that already created plant is a different error. The build writes an error and does not stay quiet. The name is created once. A later line can put letters in without writing string again, once plant already exists: plant = "leaf";. That line only replaces what the name holds. It is allowed. It is not the file you keep. The file you keep has one storing line, and that line says null.
string plant; with no = null, followed by the writing line, makes the build write an error. The name would exist as a kind, and it would hold no word yet, not even null. Put = null on the creating line, the way the file you keep has it. string plant = nullnull; treats nullnull as one name. This file does not have that name. The build writes an error. The word is null, and a missing space does not glue it into a third word that works. string plant = null ; with a space before the semicolon is still the word null. The build writes no error, and the screen is still null. The file you keep has no extra space, but that space is not a second value.
A capital letter is not the word. string plant = Null; treats Null as a name, because the first letter is a capital N. This file does not have a name Null. The build writes an error. It does not stay quiet. The screen does not show Null, because you do not run while the build is writing an error. The word in the file you keep is null, all small. Put the small letters back.
null is not a whole number
A whole number is the kind from the numbers page. int count = null; asks that kind to hold no letters. null does not fit. The build writes an error. It does not turn null into 0. It does not write null. bool ripe = null; asks the two-word kind to hold null. That kind holds true or false only. The build writes an error. It does not turn null into false. There is no screen to read, because you do not run while the build is writing an error. You do not need the exact words of these errors. Delete the int line and the bool line when you are repairing the file you keep, and write string plant = null; again.
A question after the name is a different failure, and it is not a build failure. The second file stores null, then asks how many letters that name holds.
using System;
public class Pine
{
public static void Main()
{
string plant = null;
Console.WriteLine(plant.Length);
}
}
This is the second file. It is not the file you keep. Run dotnet run. The build can stay quiet, because the lines are allowed to be in the file. The word null does not make the build fail, and Length does not make the build fail either. The program does not write a number. It does not write 4, and it does not write 0, and it does not write null. The run writes an error. You do not need the exact words of that error. The name holds no letters, so there is no count of letters to write. If the screen shows 4, plant still holds leaf, and Length is counting those four letters. Delete "leaf" and keep null, or, for the file you keep, delete Length entirely. The writing line in the file you keep is Console.WriteLine(plant); with no dot and no Length. After you have seen the error, put the kept file back.
You can now store no letters in a name and write the word null without quotes and without a digit. string plant = null; stores no letters. Console.WriteLine(plant); writes null and ends the line. Quotes around null store four letters, and the screen can look the same, so you judge the file. int count = null; and bool ripe = null; each make the build write an error. Null with a capital N is a name this file does not have. plant.Length after null lets the build stay quiet and makes the run write an error. The next page leaves this empty name. It looks at more than one value kept under a single name.
The screen is the word null
The file you keep writes null. The name on the writing line is plant, and plant is not on the screen. There are no quotes in that file. One WriteLine is one line. The same screen from quotes is four letters, not the file you keep. A digit does not belong in the file you keep. A question after the name is not the file you keep.
🧠 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