January 14, 2019
This is the fourth lab already, and you should have some habits. You should know how to
You already started to read “compile and execute” as
In the menu, click on
Build
→Build solution
(or use Ctrl + Shift + B), then onDebug
→Start without Debugging
(or use Ctrl + F5).
From now on, read “Create a new project” as
Create a new project, using the “Console Application Visual C#” template, as you did in lab 03. Pick simple and “valid” names for your project and solution, and make sure you save it in the right place. Compile and execute your program frequently, for instance upon completion of every item. Do not hesitate to change your program to answer questions: you’re in a lab, you’re supposed to conduct experiments! If you get an error when trying to compile your program, use Ctrl + Shift + F12 to “jump” to the line where VS thinks there is an error.
And, even if it is not explicitly asked, you should save your work once you are done, and re-open it at the beginning of the next session to make sure you saved it properly.
If you want an assistant or your instructor to check your answer to a previous lab, just ask!
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 realizing 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, 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.
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?
Think with a pen and a sheet of paper for some time before opening Visual Studio. Consider the following code:
int a = 0;
a = 12 - 3;
a = 10 % 3;
a = 12 * 2;
a = 9 / 3;
a = -3;
a -= 3;
a += 5;
a *=12;
a /= 2;
a = a + a;
a
after each line is executed?Main
method, use Console.WriteLine(a);
to display the value of a
after each statement.Main
method, so that when compiled and executed, you program will display the following at the screen: