This lab serves multiple goals:
In this lab, we will guide you in downloading, opening, compiling, executing and breaking (!) your very first program. It is customary to start the study of a programming language with a “Hello World” program that simply displays “Hello World”. Although such a program has no real interest nor purpose, it is used to make sure that your setup is correctly configured and to guide you gently in the discovery of programs and their language!
Download HelloWorld_Solution.zip and save it on your computer.
Go in the HelloWorld folder that was created.
Double-click on HelloWorld_Solution.sln
file
Clicking the .sln
file should launch your default C## IDE that
you installed previously or that is
pre-loaded on the computer lab you are using.
.sln
file and look for an option to
open with
, then select to open it with the IDE you installed
previously.Question:
Have you actually checked where the HelloWorld (zip) archive was hosted?
Was it on a trustworthy website? If yes, is it trustworthy because of
the domain name, because we
told you to do so, or for some other reasons?
Question:
How is an IDE different from other types of software? Identify 3
differences between an IDE and a web browser. Can you identify 3
similarities?
For this part, everything will take place inside the IDE that was started previously.
Within the IDE, first locate Program.cs
.
This file will be visible in panel called “Solution Explorer” or “Explorer”, depending on the IDE. If you do not see such panel right away, explore the IDE menus to find and open it.
After you have located Program.cs
double click on it. This is the
source code of the application you are actually considering.
Let’s compile this program. Look for an option to Build solution
and click on it. What happened?
Let’s execute this program. The exact wording varies between
different IDEs, but look for one of the following:
Debug > Start without Debugging
or Run > Start without Debugging
or Run > Run Project
and click on it. What happened?
You will extensively compile and execute programs in this class. Instead of having to click twice, it is recommended that you start memorizing shortcuts. You should study your IDE to see the exact shortcuts for your IDE for compiling and running a program. Here are the usual shortcuts for different operating systems:
Windows/Linux:
MacOS:
That makes 3 shortcuts already! You can find many more on this resource page.
Now we need to make sure you know how to save your work and access it. This is especially important if you are using the computer lab rooms, as you can not store files permanently on the lab’s computer, and you will have to store them either online in your cloud storage or on a USB drive.
You can save your project:
Having two backups is generally recommended.
If you chose the “remote” option (i.e., using a server) and are in a computer lab, do not try to install a synchronization program (like Google Drive and Sync, Box’s app, etc.) on the lab computer; it will likely not work, due to University rules. Instead, create the structure/project/files on the computer during the lab and upload them (using the web-interface) at the end of the lab. Make sure to always upload your files before logging out of the computer.
After selecting where you want to store your backup files
Create a folder for this class (CSCI1301
)
Create subfolder for the HelloWorld
lab. Put all of the files
related to the “HelloWorld” solution in this folder.
Explore your backup. Check that you have multiple folders. Specifically check that your backup contains at least the following files:
HelloWorld_Solution.sln
- this is called a solution file. It
tells the IDE how to load your C## source code in the IDE.HelloWorld_Project.csproj
- this a project file. Every C##
solution contains at least 1 project. Dividing code into multiple
project is useful for very large programs and allows integrating
projects written in different languages under the same solution.Program.cs
- this is the actual source code of your program and
where you write code.It is useful to understand the purpose and role of these different
files (.sln
, .csproj
, .cs
) when you want to backup or share
(i.e. turn in) C## programs.
Question:
Now that you understand the basic files that go into a C## program, can
you identify which files you should always include when you prepare to
submit your code for evaluation? Can you develop a strategy with a
friend, a classmate, or a second computer, to always make sure that your
submission is correctly uploaded and complete?
Once you are done, test that you performed the backup properly.
HelloWorld
folder) on the computer – or even better, share it with
a classmate and ask them to complete the following steps with you,
or do it on a different computer,If not, go have another look back at the “Compiling and Executing Your First Program” section.
If your backup went wrong (you cannot open the project, it refuses to
compile, …), try to understand what happened. Then re-download the
HelloWorld_Solution.zip
, unzip it, and make sure you can build the
solution and execute the program.
Action:
Note that for such a small project, it is easy to re-download it and use
it locally. Now imagine the program you are studying is the code of an
operating system, spanning across millions of lines of
code; such a strategy
would not be very efficient, to say the least. Yet mistakes happen, and
for that very reason, programmers generally use version
control which allows them
to undo indefinitely! Look up Distributed version
control and
try to understand its importance.
IDEs have many features and require practice. Explore your IDE and try to complete the following tasks:
Clean solution
. Cleaning is the action of removing all
generated files (e.g. the compiled program).Solution Explorer
or Explorer
and make sure you can
re-open it.If you followed the instructions carefully, you were able to build the solution and start the program without debugging after each step. As you know, C## has precise rules, and not respecting them can prevent your solution from being built by the IDE.
In this exercise, you are asked to do the following:
Change the program so that it violates one of the syntax rules of
C#
.
Build the solution, and note that an error is reported. The IDE will report a build error similar to the following:
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
If you do not see an error, look in different tabs. If you still
cannot see an error, open build output view from the IDE menu. It is
usually labelled as View > Output
, View > Tool Windows > Build
,
or similar. Then retry building the program to see the error.
Make sure you understand the meaning of the error message.
Undo your change by pressing
Windows/Linux:
Ctrl + z
MacOS:
Cmd + z
Make sure you can build the solution without a new error message.
Break your program three times, in order to identify three different error messages, and three ways of breaking C#’s rules.
If you have time or need ideas, you can try with the following and see which one(s) make the building impossible (do not forget to undo your change after):
using System
class Program
with class TestOne
}
symbol) at the
last line.Console.WriteLine
with CONSOLE.WriteLine
Console.WriteLine
with Console.WRITELINE
Console.
and WriteLine
WriteLine
and (
Write
and Line
Main()
with Method()
Be careful: some file explorers will simply preview the (zip) archive if you simply double-click on it, but most IDE will not accept to open a file if it has not been actually extracted / unzipped! ↩