This is Part 1.1 of my C# tutorial, and is basically as set of tasks which you can chose to perform based around the previous lesson, to help with your understanding.
You can do whatever you want with these tasks: Go through in detail checking each one, skim read through and guess the answers, only do the ones you’re not sure of, or skip them entirely.
I have put the ones I think are most important in bold.
Section 1 – For each task, predict whether it will result in an error, and guess what kind of error will occur. Return the program to normal after each task, especially if there was an error.
A) Put a lower case C for Console
B) Use a lower case M in Main
C) Take away the word ‘void’ from in front of the word ‘Main’
D) Remove the word ‘static’
E) Change the name of the class and take away the word ‘public’
F) Get rid of the comments
G) Remove the line that says using System;
H) Delete a semi colon
I) Get rid of the whole line which says Console.ReadLine();
J) Delete a closing curly brace
K) Delete one or both of the double quotes around the string
A) Change the string to say your name and introduce yourself, then change the class name to something meaningful with the program’s new function in mind
B) Get the program to say your name on one line and your favourite food on the next line.
HINT: Write two lines
A) Name console does not exist – C# is case sensitive
B) (Name and file path of your program) Has no entry point – there must always be a Main entry point. ‘Main’ counts but ‘main’ doesn’t because C# is case sensitive
C) Main must have a return type – every method must have a return type, even if it’s just void (nothing)
D) (Name and file path of your program) Has no entry point – The Main entry point must always be static
E) No errors – you can call a class anything you want. It doesn’t have to be public – there are other access modifiers such as private, which will be in a later tutorial
F) No errors – comments are completely optional, although obviously adding comments is a very good habit to get in to
G) Name console does not exist – You need to say you will be using the namespace System so you can use things in the class Console, because Console is in System. If you don’t tell the compiler it will need to look in System, it will not find Console. If you only use console once or twice in a large program, you could just put System.Console.WriteLine(“blah blah blah”); to call the WriteLine method, meaning you wouldn’t have to put using System at the beginning, but putting it helps with convenience.
H) ; expected – Always remember your semi colons. They tell the program when one statement ends and the next begins
I) No errors, however the program doesn’t stay around long enough to read the words on the screen – Console.ReadLine forces the program to stop before it can close itself down by getting it to wait for an input from the user. When you press enter, the input will be given and the program will end
J) } expected – Always remember to close your blocks of code so they don’t end up overlapping or going disastrously wrong
K) Multiple errors – Keep your strings inside double quotes or the program will think they’re something else
A) Simply change the string within the double quotes in the parameters of the WriteLine. The new class name should be something like ‘introduction’
B) Use two Console.WriteLine methods instead of just one
I hope you found those tasks useful. In the next part (Part 2.0) of the tutorial, we will look at how to get input from the user using Console.ReadLine()
REMEMBER YOUR SEMI-COLONS