August 17, 2020
If you are now in the computer lab on the lab computer, download on the computer the files you saved during the previous lab and make sure you can still open the project with Visual Studio (VS). Build the solution and start the program without debugging. Practicing this routinely will help you in making sure you know how to backup, transfer, and work on projects.
Close Visual Studio (VS). With the file explorer, create a new folder (call it, for instance, 02_lab) and copy the Welcome folder into it. In this exercise, you will rename and edit this copy.
Open the copy of the Welcome folder that you just created with VS. Rename the solution within VS:
.sln file change?You should not rename a solution with the file explorer: always use VS to rename.
We will now change (edit) our “MyFirstProgram” solution.
In program.cs, replace "Welcome to the lab portion of CSCI 1301!" with "This is my first program.".
Build the solution and start the program without debugging. Do you notice any change(s)?
Insert a new line after // This is an in-line comment. and before the first } sign, and paste the following:
Build the solution and start the program without debugging. Do you notice any change(s)?
Insert another new line after the one you just created and paste the following:
Build the solution and start the program without debugging. Can you notice the difference between WriteLine and Write?
Insert another new line after the one you just created and paste the following:
Build the solution and start the program without debugging. Can you tell what \t is doing?
Insert another new line after the one you just created and paste the following:
Build the solution and start the program without debugging. You should see something like this:

Can you tell what \n is doing?
Have a look the documentation page of microsoft on escape sequences and edit your program by adding a statement that displays the \ and the " characters.
Add a comment (using // or /* and */) in your program.
Make a back up of what you just did: upload the 02_lab folder you created previously on your remote backup or copy it on your thumb drive. Do not use the “Save as…” capacities of VS: close VS and copy / upload the folder “by hand” using the file explorer or a browser. Re-downloading or re-transfering it and re-opening it is a good way of making sure that your back up is correct.
This time you will not be given a project to load or to copy. You will start “from scratch”. Start by creating a folder for this lab.
We will first create a new project for Visual C# using the template for “Console App (.NET Framework)” or “(.NET Core)”; it does not make a difference for this class.
Launch Visual Studio.
Create a new project using Ctrl + Shift + N or “File” → “New” → “Project”
Find the “Console Application Visual C#” (a.k.a. “Console App (.NET Framework) Visual C#” or “(.NET Core)”; it does not make a difference for this class.) template by using Ctrl + E and then typing “Console”, or by navigating using the menu on the left panel: “Templates” → “Installed” → “Visual C#” → “Windows” → “Classic Desktop” (or “Installed” → “Visual C#” → “Classic Desktop”). If you can’t find it, follow the instructions in the note at https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-console?view=vs-2019 to install it. Complete the next step before effectively creating the project.
Enter “MyFirstProject” as the name of the project, select the right location (the best pick would be a folder you created for this lab), and enter “MyFirstSolution” as the name of the solution.
Leave the rest as is and click on “Create” or “Ok”.
Now answer the following:
Welcome project: How are they different? How are they the same?Build → Build solution. Did the compilation succeed?Debug → Start without Debugging. What happened? Compare with what happened with the Welcome project.Now you will start writing your own code. We’ll start by writing a very familiar instruction to display a message on the screen.
Place the cursor inside the Main method (i.e. after the opening brace after static void Main(string[] args)). Create a new line.
Type Console. The (at first sight annoying) auto-completion feature that displays suggestions and messages as soon as you start typing is called Intellisense. You can read about it at https://msdn.microsoft.com/en-us/library/hcw1s69b.aspx or https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense. You’ll probably end up using it a lot, but let’s not worry about that for now.
Type in .Wri after Console (don’t forget the period!) and notice that Intellisense is already making good suggestions: you actually want to write WriteLine! Either finish writing WriteLine or select it from the menu that appears.
Now type an open parenthesis, i.e. (, and notice that Intellisense closed it for you and is already displaying another message.
Type the string of your choice between those two parenthesis, i.e. something like "This is my first message" (and don’t forget the quotes).
At this point, your Main method should look like this:
Compile (build) your file. Oh no, something went wrong! Can you fix this problem?
Once you can compile your program without errors, execute (run without debugging) it.
Make a backup of your project.
The documentation for Visual Studio and C# is packed with useful information and efforts are made to make it accessible to beginners. The goal of this exercise is to help you realize that it contains answers to questions you may have asked yourself, like “what is a solution?” or “what does the namespace keyword do?”.
All the documentation for Visual Studio is at https://docs.microsoft.com/en-us/visualstudio/. The documentation for C# is at https://docs.microsoft.com/en-us/dotnet/csharp/. To get started, have a look at the first three paragraphs of https://docs.microsoft.com/en-us/visualstudio/ide/creating-solutions-and-projects (or at https://docs.microsoft.com/en-us/visualstudio/mac/projects-and-solutions?view=vsmac-2019 for Mac) and answer the following:
Note that since we will only manipulate one project at a time. The distinction between solution and project will not be critical in this lab. That’s the reason why I wrote previously “create a new project” with the sense of “create a new solution and a new project in it”: we will never manipulate more than one project in a solution at a time.
Finally, read the page at https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/. Do you know an example of namespace that we used?
Main method so that when compiled and executed, your program will display the following on the screen: