August 23, 2018
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.
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.
We will first create a new project for Visual C# using the template for “Console App (.NET Framework)”.
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 was happening with the Welcome
project.Now, you will start writing your own code. We’ll start by writing a very familiar instruction to print a message.
Main
method (i.e., after the brace after static void Main(string[] args)
). Create a new line.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..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.(
, 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:
Make a back-up of your project.
In the Main
method, add three statements:
string
variable named lastName
,string
variable named firstName
,int
variable named classOf
Assign your last name to the first variable, your first name to the second variable, and your anticipated graduation year (i.e., 2020, for instance) to the third one, using three statements.
Print the values of the three variables, using the following statement (that uses interpolation):
Compile and execute your program. It should display a message like (with your own name and graduation date, of course):
Fix it if it is not the case.String
value to an int
variable?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!