---
title: CSCI 1301 -- Lab 03
author: Clément Aubert
lang: en
fontsize: 10pt
documentclass: scrartcl
numbersections: true
links-as-notes: true
papersize: letter
geometry: margin=1in
keywords:
- Computer Science
- Problem solving methods
- Syllabus
- Augusta University
- Bachelor of Science
---


# How Was the Backup (bis)?

Re-download on the computer the files you saved during the previous lab, make sure you can still open the project with Visual Studio (VS), build the solution and start the program without debugging.
Practising this routinely will help you in making sure you know how to backup, transfer, and work on projects.

# Your First Own Project

This time, you will not be given a project to load, but you will start "from scratch".
Start by creating a folder for this third lab.

## Starting from a template

We will first create a new project for Visual C# using the template for "Console App (.NET Framework)".

#. Launch Visual Studio.
#. Create a new project, using <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>N</kbd> or "File" → "New" → "Project"
#. Find the "Console Application Visual C#" (a.k.a. "Console App (.NET Framework) Visual C#") template, by using <kbd>Ctrl</kbd> + <kbd>E</kbd> 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"). Complete the next step before effectively creating the project.
#. Enter "MyFirstProject" as the name of the project, select the right location (the folder you created for this third lab), and enter "MyFirstSolution" as the name of the solution.
#. Leave the rest as it is, and click on "Ok".
#. Now, answer the following:
 
    #. A source code appeared in the main window of VS. Compare this code with the code you studied previously: how are they different? How are they the same?
    #. Open a file explorer and navigate to the folder where you stored your project. Open the project's folder and compare it with the folder for the `Welcome` project: how are they different? How are they the same?
    #. Try to compile this code, using <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd> or `Build` → `Build solution`. Did the compilation succeed?
    #. Execute the code, using <kbd>Ctrl</kbd> + <kbd>F5</kbd> or `Debug` → `Start without Debugging`. What happened? Compare with what was happening with the `Welcome` project.

## Editing the template

Now, you will start writing your own code.
We'll start by writing a very familiar instruction to display a message at the screen.

#. Place the cursor inside the `Main` method (i.e., after the brace after `static void Main(string[] args)`). Create a new line.
#. Type `Console`. The (at first sight annoying) auto-completion feature that display 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 ending 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 appeared.
#. Now, open a parenthesis, i.e., type `(`, 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:

    ~~~~~~~{.cs}
    static void Main(string[] args)
    {
        Console.WriteLine("This is my first message!")
    } 
    ~~~~~~~

#. Compile ( = "build") your file.
Oh, no, something went wrong!
Can you fix this problem?
#. Once you can compile your program without error, execute ( = "run without debugging") it.
#. Make a back-up of your project.

# First Variables Manipulation

#. Create a new project as indicated above. Save it in the same folder as the previous one (that is, in a special folder for the third lab), and give it a different name (like "VariableManipulation").
#. In the `Main` method, add three statements:

    - One that declares a `string` variable named `lastName`, 
    - One that declares a `string` variable named `firstName`, 
    - One that declares an `int` variable named `classOf`

#. Below those three statements, write statements that assign your last name to the first variable, your first name to the second variable, and your anticipated graduation year (i.e., 2025, for instance) to the third one.

#. Print the values of the three variables, using the following statement (that uses interpolation):

    ~~~~~~~{.cs}
    Console.WriteLine($"My name is {firstName} {lastName}, and I expect to graduate in {classOf}.");
    ~~~~~~~~

#. Compile and execute your program. It should display a message like (with your own name and graduation date, of course):

    ~~~~~~~{.bash}
    My name is Clément Aubert, and I expect to graduate in 2025.
    ~~~~~~~

    Fix it if it is not the case.
#. Answer the following by first thinking of what may happen, and then editing your program to check your hypothesis.
Whould the compilation still be successful if we were to try to…
    #. … assign a value to a variable before declaring it?
    #. … display the content of a variable before assigning a value to it?
    #. … assign a `String` value to an `int` variable?
    #. … assign an `int` value to a `String` variable?

#. At the end of your main methode, add three statements that change the value of the three variables, and copy the `Console.WriteLine` statement that was previously given.
Notice that the very same statement will now print a different message!
