In Chapter 1 you'll install .NET and run your first program by typing a
command. You'll type it in a particular folder, and it will look for your
.cs file in that folder. So before any C#, make sure of two things. How are files and folders
named? How do you move around them in a window where you type instead
of click?
A file is one saved thing: a photo, a song, a page of text. Its name
often ends in a dot and a few letters, like .jpg or .cs. That ending
is the extension, and it tells you what kind of file it is. C# files end in .cs. Change the ending and you've named a different
file: hello.cs and hello.txt can sit side by side as two separate
things.
A folder is a container for files, and folders can sit inside other folders, like boxes inside boxes. Some tools call a folder a directory. It's the same thing.
A path is a file's full address, written as the list of folders you
open to reach it. Ada keeps notes on Windows at
C:\Users\Ada\Documents\notes.txt. Read it left to right: drive C,
then the Users folder, then Ada's folder, then Documents, and there's
notes.txt. Windows puts a backslash (\) between the names. Macs and
Linux use a forward slash (/).
A full address like that is called absolute. It works from anywhere,
like a complete postal address. A short one, like ch01/hello.cs, is
relative. It's more like "second door on the left": it only makes
sense once you know where you're standing. The folder you're standing in
right now is called the working directory. Two dots (..) mean
"the folder one level up," and ~ means "my home folder." You'll move
around these folders from the terminal, a window where you type
instructions instead of clicking. You'll open one a little further down
this page.
A file is a named sequence of bytes stored on disk. Its name usually
ends in an extension, a dot plus a few letters (.cs, .txt,
.dll), which tells programs and people what kind of content to expect.
The extension is part of the name: hello.cs and hello.txt are two
different files. A folder (also called a directory) holds files and other folders. The whole disk forms a tree.
A path is the address of one file or folder: the folders you pass
through to reach it, joined by a separator. Windows writes
C:\Users\Ada\csharp-course\ch01\hello.cs, with backslashes and a drive
letter. macOS writes /Users/Ada/csharp-course/ch01/hello.cs and Linux
/home/ada/csharp-course/ch01/hello.cs, with forward slashes and no drive.
Those are absolute paths: they start at the top of the tree. They mean the same thing no matter
where you are.
A relative path, such as ch01/hello.cs, has no starting point of
its own. It is read from the working directory (also called the
current directory), the folder a program is currently "in." Two special
names help: . means the working directory itself, and .. means the
folder that contains it. ~ is shorthand for your home folder. The
terminal is a text window for working with all of this by typing
commands; the second half of this section opens one.
Works anywhere, or depends where you are?
Sort each path: does it name the same place from any folder, or does it depend on the working directory?
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
C:\, or a leading /) or at your home folder (~) work from anywhere. ch01/hello.cs, hello.cs, and .. are all read from the folder you're in.Worked example
Following a relative path
-
1
Ada's working directory is
/Users/Ada/csharp-course. She asks for the filech01/hello.cs. -
2
A relative path starts from the working directory, so glue the two together:
/Users/Ada/csharp-course+/+ch01/hello.csgives/Users/Ada/csharp-course/ch01/hello.cs. The file is there. -
3
Now she moves into
ch01and asks forch01/hello.csagain. Glued together, that's/Users/Ada/csharp-course/ch01/ch01/hello.cs. There's noch01folder insidech01. The file isn't found. -
4
Same words, different result, because the starting point moved. From inside
ch01, the right relative path is justhello.cs. The absolute path would have worked from both places.
Worked example
Going up with ..
-
1
Ada is in
/Users/Ada/csharp-course/ch01and wants thech00folder, which sits besidech01, not inside it. -
2
..means "one folder up," which fromch01iscsharp-course. -
3
So
../ch00means: go up tocsharp-course, then down intoch00. That lands on/Users/Ada/csharp-course/ch00. -
4
On Windows the same trip is written
..\ch00. PowerShell also accepts forward slashes, so../ch00works there too.
Check your understanding (counts toward your progress)
Ada's working directory is /Users/Ada/csharp-course/ch01/notes. How many times must she type cd .. to reach /Users/Ada? Type the number.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Why
notes → ch01 is one, ch01 → csharp-course is two, csharp-course → Ada is three.
Correct answer
Also accepted:
Why
Each cd .. removes the last folder name from the path.
In one terminal, ch01/hello.cs finds the file. In another terminal window, the same path says the file doesn't exist. What's the likeliest reason?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Possible, but nothing points to it. A relative path failing in one window and working in another is the classic sign of a different starting folder.
Every terminal reads relative paths the same way, from its own working directory.
Extensions are written the same way in both. The difference is where each terminal is standing.
Why
A relative path is read from each terminal's own working directory. Run pwd in both and you'll see they're in different folders.
What does a relative path start from?
Put these pieces in order to build the Windows path to hello.cs, from the top of the tree down.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
An absolute path lists every folder from the top down: drive C, Users, Ada, csharp-course, ch01, and then the file itself.
Correct answer
Also accepted:
Why
Start at the drive and open one folder at a time until you reach the file.
What does ~ stand for in a path like ~/csharp-course?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
The folder you're in is written ., a single dot.
The very top is / on macOS and Linux, or a drive like C:\ on Windows.
One level up is ...
Why
~ is shorthand for your home folder, so ~/csharp-course names the same place no matter where you are.
It's the folder every new terminal starts in.
Open a terminal and move around
The terminal is a window where you talk to your computer by typing. You type an instruction, called a command, press Enter, and the computer does it. Windows calls its version PowerShell, and it runs inside an app called Windows Terminal. A Mac has an app called Terminal, and Linux desktops have one too, usually with "Terminal" in its name. The details differ. The idea doesn't.
A command is a verb, and what comes after it says what to work on. With
mkdir ch01, the verb is mkdir ("make directory," that is, make a
folder) and ch01 is the name of the folder to make.
The terminal is always "standing in" one folder, the working directory. When you open a new terminal, that's your home folder. Four commands do almost everything you'll need at first:
pwdasks "where am I?" and prints the folder's full address. The letters stand for "print working directory."lsasks "what's in here?" and lists the files and folders. On Windows,dirdoes the same job.mkdirmakes a new folder.cdmeans "change directory": it moves you into another folder.cd ..moves you up one level.cd ~takes you home.
One surprise for beginners: when a command works, it often prints nothing at all. Silence means success. When something goes wrong, you get a message.
A terminal is a window that runs a shell: a program that reads
a line you type, called a command, runs it, and prints any result.
The default shells are PowerShell on Windows (inside the Windows
Terminal app), zsh on macOS, and usually bash on Linux. A command starts
with its name, and anything after it, separated by spaces, is an
argument that tells the command what to act on: in mkdir ch01,
mkdir is the command and ch01 is its argument.
Four commands cover this course's early needs, and they work in all
three shells. pwd prints the working directory. ls lists the
contents of the working directory (PowerShell also accepts dir).
mkdir name makes a new folder. cd path changes the working directory
to path, which may be absolute or relative; cd .. moves up one level
and cd ~ goes home. Every new terminal starts in your home folder. A
command that succeeds often prints nothing; a failure prints an error
message.
Press the Start key, type Terminal, and press Enter. Windows Terminal opens with a PowerShell prompt. (On an older Windows 10 machine without it, search for PowerShell instead.) Type these one at a time, pressing Enter after each:
cd ~
mkdir csharp-course
cd csharp-course
pwd
~ is your home folder, C:\Users\<your name>, so the path pwd
shows should end in \csharp-course. mkdir prints a short table about the folder it made;
that's PowerShell being chatty, not an error.
Press Cmd+Space, type Terminal, and press Enter. Type these one at a time, pressing Enter after each:
cd ~
mkdir csharp-course
cd csharp-course
pwd
~ is your home folder, /Users/<your name>, so pwd should end in
/csharp-course.
Open your applications menu and search for Terminal (on many desktops, Ctrl+Alt+T opens one directly). Type these one at a time, pressing Enter after each:
cd ~
mkdir csharp-course
cd csharp-course
pwd
~ is your home folder, /home/<your name>, so pwd should end in
/csharp-course.
Whichever system you're on, ls now lists nothing, because the new
folder is empty. In Chapter 1 you'll save hello.cs here and ls will
show it.
Which question does each command answer?
Sort each command by the job it does.
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
pwd answers where you are. ls and dir list what's there. cd with any path, including .. and ~, moves you. mkdir makes a folder but leaves you where you were.Worked example
Where am I, and what's here?
-
1
Open a fresh terminal and type
pwd. It prints your home folder, because every new terminal starts there. -
2
Type
cd csharp-course. Nothing is printed. That's success. Typepwdagain. The path now ends incsharp-course. -
3
Type
mkdir ch01, thenls. The listing showsch01.mkdirmade the folder but didn't move you into it:pwdstill ends incsharp-course. -
4
Type
cd ch01, thenpwd: now you're inside.cd ..takes you back up tocsharp-course.
Worked example
When cd can't find the folder
-
1
Ada opens a new terminal and immediately types
cd ch01. Instead of silence, she gets an error saying the folder can't be found. (The exact wording differs between PowerShell, zsh, and bash.) -
2
ch01is a relative path, so it's read from the working directory. A new terminal starts in the home folder, andch01isn't in the home folder. It's insidecsharp-course. -
3
Two ways out:
cd csharp-coursefirst and thencd ch01, or give the path from home in one go withcd csharp-course/ch01. -
4
When
cdfails, typepwdandlsbefore anything else. They tell you where you really are and what's there.
Set up a folder for Chapter 1
Put the commands in order: start from your home folder, go into csharp-course, make a folder called ch01 there, go into it, and check where you ended up.
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
cd ~ puts you at home. You must be inside csharp-course before mkdir ch01 so the new folder lands there. Then cd ch01 enters it, and pwd confirms the path ends in csharp-course/ch01.Professional habit: name folders and files without spaces, like
csharp-course or grade-report.cs. A space splits a command's
arguments, so a folder called my course has to be typed in quotes,
cd "my course", every single time.
Where this goes next
Chapter 1 §2 has you open this same terminal and type dotnet --info to
check the install. Chapter 1 §3 runs dotnet run hello.cs from inside your ch01 folder.
It finds the file only because hello.cs is a relative path, read from
the working directory. Chapter 1 §4 makes your first project in a folder of its own. You'll
cd into it to build and run it.
Check your understanding (counts toward your progress)
Sort each command by the job it does.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
pwd shows the working directory, ls and dir list it, every cd moves you, and mkdir makes a folder.
Correct answer
Also accepted:
Why
What does cd ~ do?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Going up one level is cd ...
cd moves you; it doesn't list anything. ls lists.
Making folders is mkdir's job, and ~ is a shorthand, not a name.
Why
~ means your home folder, so cd ~ takes you there from anywhere.
From your home folder: make a folder called games, go into it, make a folder called snake inside it, go into that, and print where you are.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Each folder is made, then entered. snake lands inside games only because you were in games when you made it; pwd confirms the path ends in games/snake.
Correct answer
Also accepted:
Why
A folder has to exist before you can cd into it.
You're in csharp-course/ch01 and want to see what's inside ch00, which sits beside ch01. Order the commands. One doesn't belong.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
cd .. climbs to csharp-course, cd ch00 goes down into the sibling, and ls lists it. ch00 already exists, so mkdir is the extra step.
Correct answer
Also accepted:
Why
ch00 already exists. You just need to get to it.
Practice: Find your way around the terminal (5 problems · doesn’t affect your progress)
In cd csharp-course, which part is the command and which is the path?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
The verb comes first. cd is the instruction; the folder name is what it acts on.
A path names a place. cd names an action.
Only cd is an instruction. csharp-course is a folder name.
Why
The command comes first and says what to do. The path after it, its argument, says where.
cd is the command; csharp-course is the path
Which command shows the full path of the folder you're in?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
ls lists what's inside the folder, not where the folder is.
mkdir makes a new folder.
cd moves you to another folder.
Why
pwd stands for print working directory: it prints where you are.
pwd
From your home folder, make a ch02 folder inside csharp-course, go into it, and confirm where you are.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Enter csharp-course first so mkdir ch02 creates the folder there, then move in and check with pwd.
Correct answer
Also accepted:
Why
Where must you be standing when you make ch02?
You're in /home/ada/csharp-course/ch01. Where does cd ../ch02 take you?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
The .. comes first, so you go up out of ch01 before going down into ch02.
.. goes up one level only, to csharp-course, not two.
Without a leading /, the path is relative, so it doesn't start at the top.
Why
.. takes you up to csharp-course, then ch02 goes down into its ch02 folder.
Do the .. part first, then the ch02 part.
/home/ada/csharp-course/ch02
The folder is named ch01, all lower case. You type cd Ch01 with a capital C. What happens?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Linux treats Ch01 and ch01 as two different names, so there it fails.
Windows, and macOS in its usual setup, ignore capitals in folder names, so there it works.
cd never creates folders.
Why
Linux file names are case-sensitive, so Ch01 isn't ch01 there. Windows and the default macOS setup ignore case in names. Typing names exactly avoids the question, and C# code itself is case-sensitive everywhere.
Linux treats capitals differently from Windows and macOS.
On Linux it fails; on Windows, and usually on macOS, it works