Pre-bootcamp Learner Notes
Once you’ve followed the Pre-course Introduction section, follow through these tutorial videos and self-guided exercises. This will ensure that you’ve got a grounding in the fundamentals of the C# language and Git, so that you’re ready for Bootcamp.
1. Your first C# program
Watch the following videos from the Microsoft Virtual Academy. Remember that throughout these videos they are using Visual Studio to demonstrate, while we will be using Visual Studio Code. The VSCode interface is similar to but simpler than Visual Studio.
Prior experience
If you have significant prior experience:
- You may want to watch the Course Introduction to get a flavour for the course.
- If you already know how to write a “Hello, World” type program in C#, you can skip the other videos and go straight on to the exercises. Even if these first exercises seem trivial it’s best to do them since we’ll be building on these programs soon.
If you feel you’re somewhere short of “significant” experience, but still find it all fairly obvious, remember the “2x speed” option on the video. You’ll get used to the change in pitch quite quickly!
Exercise 1.1
As we progress through this section, we’re going to work through and build a very simple Calculator application. It will be a console (command line) application and so entirely text based. Here’s how to get started:
- Create a new folder for your project (say
C:\Work\Training\Calculator
) and then open it in VSCode (File > Open Folder…) - Open a terminal console in VSCode (Terminal > New Terminal)
- Run the following command:
dotnet new console --framework net6.0 --use-program-main
You should see some code in Program.cs that looks like:
namespace Calculator;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
- We’ll discuss what the
namespace
,class
, andMain
lines mean later on. For now, just make sure that all the code you want to run is inside the pair of curly brackets understatic void Main
. - Change your code to print out a welcome message for your calculator app – e.g. “Welcome to the calculator!”.
- Run the program and check that it works:
- Click the Play/Debug button on the left of the window or F5 key
- Build Assets
- Click the green play button near the top of the screen
- You should see the program output in the terminal within VSCode
The ‘Creating Your First C# Program’ tells you to put the line Console.ReadLine() at the end of the program so the output window doesn’t disappear immediately. This is no longer necessary so you can leave it out.
Exercise 1.2
So far all the code you’ve looked at will always output the same thing every time it’s run. If we want the user to control what the program does we can read input from the command line, using the Console.ReadLine
method:
string aFriend = Console.ReadLine();
Create a new project in the same way you did before and give it a suitable name – say, “Greeting”. Write a program which displays a message asking the user their name, accepts some input, and then prints “Hello, [ name ]. Nice to meet you!” where [ name ] is the name they entered. Make sure to save it as we’ll come back to modify it later.
Exercise 1.3
Having started your Calculator program, we want to put it on GitHub for all the world to see. Or at least, so your tutor can take a look in due course. In git, each project generally lives in its own ‘repository’. Here’s how to create one:
- Go to GitHub
- Click the green “New” button to start creating a new repository
- Enter a suitable name for your repository – “Calculator” would do! Make sure the “Owner” is set to your name. Enter a description if you like too.
- It would be handy to “Add .gitignore” – choose “VisualStudio” as the template. (.gitignore is a file describing the types of files that shouldn’t be stored in git; for example, temporary files or anything else that shouldn’t be shared with other team members. You pick a Visual Studio-specific one so it’s preconfigured with all the files Visual Studio will create that really shouldn’t be stored in git).
- Leave everything else at the defaults. In particular you want a “Public” project, unless you want to pay for the privilege.
- Click “Create repository”.
That gives you a (nearly) empty repository. Now you want to link that up to your Calculator. Open up Git Bash (or your command line utility of choice). Navigate to where your Calculator lives (e.g. cd C:\Work\Training\Calculator
, or right-click and use ‘git bash here’). Then run the following commands:
git init
git remote add origin https://git@github.com:YourName/Calculator.git
git fetch
git checkout main
Replace “YourName” in the above with your GitHub username. You can find the correct text to use by clicking the green “Code” in your project on GitHub and then finding the “Clone with HTTPS” URL.
We’ll discuss these git commands later in the Bootcamp, and for now you don’t need to worry about what they do exactly. Broadly what we’re doing is setting up a local repository that’s linked to the one on GitHub so changes you make can be uploaded there.
If you’re using a GitHub account you created in 2020 or earlier, you may need to replace main
with master
above because that used to be the default branch name. If you’ve just signed up for GitHub now that won’t be an issue.
You should find that there are no errors, and that the .gitignore
file that you asked GitHub to create now exists locally. However if you refresh your web browser on your GitHub project you’ll see that hasn’t changed – the Calculator code is only on your local machine. You can fix this by running this in your command prompt:
git add .
git status
git commit -m "My first piece of C# code"
git push
Now refresh your GitHub browser window and your source code should be visible!
Again, we’ll discuss what these are doing later – for now just remember that you should run these four commands, replacing the text in quotes with a short summary of what you’ve changed, every time you’ve made a change to your code and want to update your GitHub repository with that change.
When you’re prompted to submit your answers exercises during the course, you can just supply the GitHub link – something like https://github.com/YourName/Calculator
. Your trainer can see the code, and provide feedback on it if appropriate. You don’t need to submit anything at this stage, you can move on to the next exercise.
Some notes on git
For the time being, you don’t need to worry too much about what the various commands above actually did. However, here are some details to satisfy your curiosity:
git init
: Turn the current directory into a git repository on your local machine. A hidden directory .git is created to manage all the git internals – the rest of your files stay unchanged.git remote add origin git@github.com:YourName/Calculator.git
: Git is a distributed version control system. Your local machine contains a complete and working git repository, but other people can also have a complete and working copy of the git repository. If one of those “other people” is GitHub, that provides a convenient way of sharing code between multiple people. This line just says that GitHub (specifically, your Calculator repository) should have a remote copy, and we’re naming that copy “origin”. The name “origin” is just a git convention meaning “the main copy” – but actually you could use any name, and Git doesn’t really do anything special to make one copy “more important” than another.git fetch
: This downloads all the latest changes from GitHub. In this case, that means downloading the .gitignore file to your machine. But it’s not visible on your local machine yet…git checkout main
: This tells Git which version of the code you want to see. The “main” branch is the main copy of the code that’s currently being worked on. You’ll notice “Branch: main” is displayed in GitHub too – you can create multiple branches to track progress on different features under development, and this is useful if several people are working on your code at once.git add .
: This tells Git to record the changes made to all the files at.
which means the current working directory; you could equally well specify each individual file by name.git status
: This doesn’t actually do anything, but displays the current status of your repository – you should see some files listed as being changed and ready for commit.git commit -m "My first piece of C# code"
: This tells Git to save those changes in its history. That way you can go back to this version of the code later, should you need to. Git provides a history of everything that’s happened. The-m
precedes a message which explains the purpose of the change.git push
: This sends all the changes stored in your local repository up to GitHub. It’s just like the earliergit fetch
, but in the opposite direction.
If you want to see the history of your commits, click on the “commits” label in GitHub, or run git log
locally. There’s also a local graphical view by running gitk
.
2. Data types and variables
Watch the following videos:
- Working with Code File, Projects and Solutions – remember that in our course we use VSCode as the IDE rather than Visual Studio, so the descriptions of the user interface will be different
- Understanding Data Types and Variables
Prior experience
If you’re familiar with data types and variables in C#, test yourself on the exercises below. If you can do it all easily, it’s fine to skip the rest of the second video.
Exercise 2.1
Write a program to calculate and display the area of a circle with a radius of 2.5 units. You can use the inbuilt constant Math.PI
for the value of pi.
Exercise 2.2
Improve your program to ask the user for a radius, then output the area of the corresponding circle. Since Console.Readline
always inputs a string, you’ll need to convert it as follows:
double radius = Double.Parse(myString);
What do you think will happen if the user enters something other than a number? Try running your program and see!
Exercise 2.3
Add the following functionality to your Calculator project:
- Prompt the user to enter one number
- Prompt the user to enter a second number
- Multiply the two numbers together and print out the result
Once you’ve got your program working, commit the changes to GitHub. You should be able to follow the same steps as last time (from git add
onward), or here’s an abbreviated version:
git commit -a -m "Added a simple multiplier"
git push
The -a
argument to git commit tells Git to first add any changes, and then commit them. Note that this only works if Git already knows about the files – it won’t pick up any newly created files.
3. Branching
Watch the following videos:
Prior experience
Here are the key things you should be learning from the videos. If you’re already familiar with these concepts in C#, it’s ok to skip the videos and just complete the exercises.
if(condition) { } else if(condition2) { } else { }
- The difference between
a == b
anda = b
- Joining strings together with
string1 + string2
- Variable declaration (
int a
) and assignment (a = 3
)
Exercise 3.1
Open the Greeting program you wrote in Exercise 1.2 and update it to do the following:
- Ask the user for a first name and surname separately then print a greeting, e.g. “Hello, Anne Smith!”
- If the user enters a blank input for either name, output a message commenting on the fact, e.g. “Hello, Anne! I see you only have one name, but that’s fine!”
- If the user enters a blank input for both names, output a message complaining that the user isn’t cooperating
Exercise 3.2
Update your Calculator program to support more operations than just multiplication, by promopting the user for an operator before they enter the numbers. So a typical program run might look like this:
Welcome to the calculator!
==========================
Please enter the operator: +
Please enter the first number: 10
Please enter the second number: 4
The answer is: 14
To keep things simple, we’ll just use four operators:
+
– addition-
– subtraction*
– multiplication/
– division
There are lots of ways to solve this, although not many have been covered in the videos yet. Feel free to do something fancier than simple if
-statements if you wish! Perhaps you could make a Git commit after each so you can review the different approaches later.
Make sure you git push
when you’re done so your trainer can see the results.
4. For loops and arrays
Watch the following videos:
Prior experience
Here are the key things you should be learning from the videos. If you’re already familiar with these concepts in C#, it’s ok to skip the videos and just complete the exercises.
for (int i=0; i<10; i++) { }
foreach (int value in list)
- Using
break
andcontinue
to control loop behaviour - Creating arrays using
new int[4]
andnew int[] {1,2,3,4}
- Accessing arrays using
array[2]
- Treating strings as character arrays using
toCharArray
Exercise 4.1
Write a program that will accept an integer input from the user, and find the sum of all integers from 1 up to that value (for example, the input 4 should give output 10).
Exercise 4.2
Create a program to display a set of times-tables, starting at 2 and going up to a number chosen by the user. For example, if the user enters 4 the output might look like this:
2 x 2 = 4
3 x 2 = 6
4 x 2 = 8
2 x 3 = 6
3 x 3 = 9
4 x 3 = 12
2 x 4 = 8
3 x 4 = 12
4 x 4 = 16
Exercise 4.3
Modify the Calculator so it can do calculations on any number of numbers. For example:
3 + 4 + 5 = 12
1 * 2 * 3 * 1 = 6
120 / 10 / 2 / 2 = 3
Let’s keep things simple by using the same operator each time. So a typical output might look like this (for the first sum above):
Welcome to the calculator!
==========================
Please enter the operator: +
How many numbers do you want to +? 3
Please enter number 1: 3
Please enter number 2: 4
Please enter number 3: 5
The answer is: 12
See what you can come up with, and push the result.
Exercise 4.4 (extension)
Create a program which inputs a number, then inputs that many words, then outputs each of them in reverse order. For example:
Enter number of words: 3
Enter a word: I
Enter a word: love
Enter a word: programming
Your sentence is: I love programming
Your reversed words are:
I
evol
gnimmargorp
Exercise 4.5 (extension)
Create a program that asks for an integer input and outputs whether or not that number is a square number. (C# has a method called Math.Sqrt()
for finding square roots, but don’t use that for this exercise!)
5. Methods and while loops
Watch the following videos:
Prior experience
Here are the key things you should be learning from the videos. If you’re already familiar with these concepts in C#, it’s ok to skip the videos and just complete the exercises.
- Defining your own static method
- Calling a static method, with parameters
- Returning values from methods
while (condition) { }
Don’t forget to go back and look at the videos if anything in the exercises is puzzling!
Exercise 5.1
Create a program which keeps accepting input words and putting them together into a sentence until the user enters a blank input. For example:
Enter a word: I
Current sentence: I
Enter a word: love
Current sentence: I love
Enter a word: programming
Current sentence: I love programming
Enter a word:
Final sentence: I love programming
Exercise 5.2
One of our goals as programmers should be to write “clean code” – that is, code that is simple and understandable. Take a look at this piece of code:
static void Main(string[] args)
{
PrintWelcomeMessage();
PerformOneCalculation();
}
It’s hopefully fairly obvious what this code is trying to do. Refactor your Calculator code so it looks the same as this example – that will involve splitting your existing code into two new methods, and then having the Main
method just call them both in turn.
“Refactoring” is the process of improving your code without changing its behaviour. Those improvements might be to make it more readable, or to make it easier to change and extend in future.
Exercise 5.3
Your Calculator probably has at least a couple of pieces of code of the form:
Console.Write("Please enter a number: ");
string answer = Console.ReadLine();
int number = int.Parse(answer);
Create a method that encapsulates this pattern, and use it to replace all the code that’s similar to the above. The same method should be usable every time you want to print out a message and interpret the response as an integer.
Exercise 5.4
Make your calculator keep running – once it’s calculated an answer, it should just loop round and start again. Presumably you don’t want to keep printing the welcome message every time though.
Exercise 5.5
Force the user to enter valid numbers – when prompting for an integer, it’s annoying if your program crashes if the user types in a string instead. Have it just ask again in this case.
For this you might find the int.TryParse method useful. It tries to interpret a string as a number, and returns false if it fails or true if it succeeds:
int answer;
if (int.TryParse("42", out answer))
{
// It worked! We can use answer here
}
else
{
// It didn't work... Don't try to use answer because it's not be set yet
}
Don’t worry about the out
keyword for now – it just allows the TryParse
method to return the answer as well as the true / false value. Having a method return two values isn’t normally a good idea, but this is one case where it’s a real improvement.
Once you’ve got all that working, push it to GitHub before you move on.
6. Strings, dates and times
Watch the following videos:
Prior experience
This topic’s videos are quite short, particularly if you run them at 2x speed. They contain some snippets that are probably interesting to all but C# experts, so our recommendation is to watch them through. Who knows, perhaps they’re getting interesting even if the earlier ones were a bit basic for you?
Having had a quick skim through them you can use the exercises below to check your understanding.
Exercise 6.1
Update the Greeting program you wrote earlier, so that:
- If the user inputs their name in all capitals, the program tells them “no need to shout!” – but still displays the greeting with their name in all lower-case
- If the user’s full name is longer than 12 characters, the program comments on it being a long name
- The program also asks for the user’s birthdate, and displays a different greeting if they are under 10 years old
Exercise 6.2
Review how your calculator deals with strings at the moment. Can you use string.Format to improve your code? Perhaps try adding some more informative text now that you have a neat way to print it out.
Console.WriteLine
has an overload (alternative version) that takes exactly the same parameters as string.Format
– so if you’ve written Console.WriteLine(string.Format(...))
, you can replace it with just Console.WriteLine(...)
. You might be able to take advantage of this shortening from time to time.
Exercise 6.3
We’d like to enhance the calculator to operate on dates as well as numbers. Specifically, we’ll add support for taking a date, and adding a number of days to it. Working with dates doesn’t really fit into the current interface, so we’ll modify our Main
method to look something like this:
private const int NumberCalculator = 1;
private const int DateCalculator = 2;
static void Main(string[] args)
{
PrintWelcomeMessage();
while (true)
{
int calculationMode = AskForCalculationMode();
if (calculationMode == NumberCalculator)
{
PerformOneNumberCalculation();
}
else
{
PerformOneDateCalculation();
}
}
}
And the output might look something like this:
Welcome to the calculator!
==========================
Which calculator mode do you want?
1) Numbers
2) Dates
> 2
Please enter a date: 7/2/17
Please enter the number of days to add: 2
The answer is: 09/02/2017
Which calculator mode do you want?
1) Numbers
2) Dates
>
Implement some function along these lines. You’ll need DateTime.TryParse
, which works much like the int
equivalent.
7. Classes
Watch the following videos:
- Understanding Classes
- More About Classes and Methods
- Understanding Scope and Accessibility Modifiers
Prior experience
Here are the key take-aways from each of the videos:
- Understanding Classes: Creating your own class, with properties (
get
andset
) and methods. You should know the difference between a property and a method. - More About Classes and Methods: Object instances, references and
null
values. The difference between static and instance methods. - Understanding Scope and Accessibility Modifiers: Why in
for(int i=0; i<10; i++)
you cannot accessi
outside of the loop. Why you cannot declare two variables of the same name in the same method. The difference betweenprivate
,public
,protected
andinternal
.
If you have lots of prior C# experience and could confidently explain all the above, then it’s ok to skip the videos and go straight on to the exercises. Otherwise it’s best to watch the videos though, even if you do so on 2x speed.
Exercise 7.1
In your Greeting program, create a new Person
Class. Modify your existing code so that all the user inputs and displaying the greetings are done by methods on this class. What properties does your class need?
Exercise 7.2 (extension)
Your Greeting program needs to perform several checks to decide what to say to a user. Create a new method for each of these checks – for example, one might be called IsUnderTen()
and return true if the Person is aged under 10 (it’s common for methods that return booleans to have names beginning with ‘Is’). Think about the appropriate access level for each of these methods.
Exercise 7.3
Your Calculator application is getting quite large. Hopefully you’ve split it up into reasonably small and self-describing methods, but that’s still a lot of code to lump together into a single file. Let’s split it up a bit.
A sensible structure for your Calculator program would be the following:
- A main class, which you might leave with the default name
Program
, which contains theMain
method and works out whether you want numbers mode or dates mode. - A separate class that deals with number calculations. Perhaps
NumberCalculator
. - Another class that deals with date calculations. Perhaps
DateCalculator
.
Try separating your application into classes like this.
Here are some additional questions to answer as you go:
- What challenges do you face? – what do you find that’s not satisfactory or straightforward? How do you overcome these challenges?
- How many of your methods need to be static? – see how few you can get away with.
8. Namespaces and references
Watch the following videos:
- Understanding Namespaces and Working with the .NET Class Library
- Creating and Adding References to Assemblies
Prior experience
Most of the video content this time is about the practicalities of handling multi-project solutions within Visual Studio, and importing references to other libraries. They’re worth a skim (i.e. double speed if you feel you know most of it already) even if you have prior experience in writing the actual C# code.
Exercise 8.1
The videos demonstrate how to write some text to a file. The method used just replaces the entire file though. Do some searching in the Microsoft documentation to work out how you can append text to a file. Use this knowledge to add a log to your Calculator program – it should record every calculation performed. Ideally:
- Clear the log when the program starts up
- Print each calculation as a separate line in the log file
- Create your logging code in a separate class, avoiding static methods where possible, to make it reusable in future
9. Collections and LINQ
Watch the following videos:
Prior experience
Here are the key things you should be learning from the videos. If you’re already familiar with these concepts in C#, it’s ok to skip the videos and just complete the exercises.
- The difference between an
ArrayList
and aList<T>
- Creating, populating and accessing a
List<T>
- Creating, populating and accessing a
Dictionary<TKey, TValue>
- Using LINQ expressions such as
list.Where(p => p.Property == 42)
- The alternative LINQ syntax
from p in list where p.Property == 42 select p
Don’t forget to go back and look at the videos if anything in the exercises is puzzling!
Exercise 9.1
Change your Calculator so that it stores all the numbers for a single calculation in an array (if it doesn’t already) and uses a LINQ query to compute the result.
To get you started, here are a few useful methods:
Sum
– adds up all the numbers in a collectionAggregate
– applies an operation repeatedly to all the values in a collection. Each result is passed as an input to the next operationSkip
– returns a collection which consists of everything in the original collection, except the first N elements
You’ll want to look up the details in the Microsoft documentation. There are other methods that may be useful so feel free to hunt them down too, although the above would be enough to complete the challenge.
Exercise 9.2
You can keep using arrays, as pointed out above, but just for practice try replacing all your arrays with List
s. Use this as an opportunity to avoid having to ask how many numbers to add up up-front – e.g. the output would look something like this:
Welcome to the calculator!
==========================
Which calculator mode do you want?
1) Numbers
2) Dates
> 1
Please enter the operator: +
Please enter the numbers to +.
Please enter the next number: 1
Please enter the next number: 2
Please enter the next number: 3
Please enter the next number:
The answer is: 6
As usual there are many ways to do this. But you might find it useful to use a “nullable int”. This data type is written int?
. It works just like a normal int
, except that it can take the value null
, meaning “no value”. An int?
has two properties: HasValue
tells you whether it has a value or not (you can also use == null
to test this), and Value
gets the actual value out as a regular int
. You can solve this exercise without using nullable ints, but you might find you can write neater code if you use one.
10. Enums, switch statements and exceptions
Watch the following videos:
Prior experience
Here are the key things you should be learning from the videos. If you’re already familiar with these concepts in C#, it’s ok to skip the videos and just complete the exercises.
- How to define and use an
enum
- The
switch
statement, includingdefault
andbreak
- What happens to your application if there’s an unhandled exception
- How to catch specific exception types and take action
Exercise 10.1
Your Calculator probably has a block of code that consists of a series of if
-tests to decide which operation to carry out (+
, -
, *
, /
). Replace this with a switch
statement.
This may highlight, if you haven’t already handled it, the fact that the user might enter an operation that isn’t supported. Let’s handle that case using an exception:
- Have your code throw an exception in this case. You can cause an exception to happen using
throw new Exception("Helpful message")
. (In practice you’d probably want something more specific than justException
, like the examples in the video. Feel free to do some research on how to define your own exception class for this scenario, and throw that instead). - Run your code and check that the program now fails in a suitably fatal manner.
- In your main program loop, handle that exception via
try...catch
, print out a suitable error message, and keep the program going. - Run your code again, and check that the exception is no longer fatal!
Exercise 10.2
If you followed the sample code in an earlier exercise, your main loop consists of a couple of constants (const
) to decide between number and date calculations. Replace these constants with an enum
to achieve the same effect.
There are (at least) two ways to convert an integer typed in by the user to an enum
value. Firstly, assign numeric values to your enum values by putting e.g. = 1
after the value. Then you can either “cast” (convert) an integer to an enum using EnumType enumValue = (EnumType)integerValue
, or you can use the Enum.TryParse
method. You may need to do a little digging in the documentation to get more details!
11. More challenges
There is one more video in the Microsoft Virtual Academy which will be useful:
Pick one of the following exercises to explore further. Or feel free to do several of them if you’re feeling keen!
A Calculator UI
The event handling video gives a very brief glimpse into how to build a UI using XAML. The simplest possible calculator UI would probably consist of a text box to enter your operator (+
, -
, etc.), another text box to enter a list of numbers (if you ask for the separated by commas, you can use string.Split(',')
to divide this up into an array), a button to trigger the calculation, and a label to display the result in. You should have all the individual pieces of knowledge need to build this UI now, but don’t expect it to be too easy to string everything together at the first attempt!
An ICalculator interface
Your Calculator has two classes that expose the same interface to the outside world – both the NumberCalculator
and DateCalculator
(if you kept the original name suggestions) probably have a public-facing method that prompts the user for input and then performs a calculation.
Let’s formalise this interface, using a C# interface. If we assume both your classes have a method called PerformOneCalculation()
, we can define this interface:
public interface ICalculator
{
void PerformOneCalculation();
}
Now modify your class definitions as follows:
public class NumberCalculator : ICalculator
This announces that the NumberCalculator
“implements” the ICalculator
interface. Any variable of type ICalculator
can hold a new NumberCalculator()
and call its PerformOneCalculation
method. But it can also hold a DateCalculator
, if that implements the same interface.
See if you can use this to neaten up any of your code. For example, perhaps the Main
method could create a Dictionary
of calculators, and look up the appropriate calculator in this to avoid repeated if
-tests or a switch
statement.
Simpler string formatting
You’ve learnt about string.Format
. The latest versions of C# include a cleaner syntax, not mentioned in the videos. This is known as “string interpolation”. You can replace this code:
int[] values = new int[] { 1, 2, 3};
string test = string.Format("Testing, {0}, {1}, {2}", values[0], values[1], values[2]);
with this:
int[] values = { 1, 2, 3 };
string test = $"Testing, {values[0]}, {values[1]}, {values[2]}";
The $
-syntax means that anything in {brackets}
is replaced with the corresponding variable / expression.
Applying this throughout your code should be straightforward, and hopefully makes it look that little bit neater. Neatness is good – can you find any other ways in which your code could be tidied up or simplified, based on your existing knowledge?
More comprehensive error handling
How carefully have you reviewed and tested your code to make sure it will work in every case? Here are some scenarios you could test and see what happens:
- Enter an invalid value when prompted for a calculation mode (number of date)
- Enter an invalid number operation
- Enter an invalid number
- Enter an invalid date
- Try to multiply some very large numbers (e.g. to create an answer over 2 billion)
- Try to divide by zero
You’ll be doing well if none of these cause a problem. Can you fix them all up? Can you find any other error cases?
12. Conclusion
Beyond the tutorials and exercises you’ve done so far, the best way to continue learning is by doing.
A programming kata is a practice piece – a relatively simple problem where the goal is just to practice solving it in different ways, and hence develop your expertise. You can start of course by just solving the problem once, any old how – if you’re still learning C#, that experience has taught you something. But once you’ve done that, how about trying it again in a different way. Could you use LINQ, or divide the problem into classes / methods differently? What happens if you change the problem (e.g. supply different inputs, or ask a slightly different question in the output) – how easy is your code to adapt? Here are a couple of kata to start you off:
Another fantastic source of learning is your job, which presumably involves programming. If you didn’t know C# at all before taking this course, you probably haven’t actually done much programming yet… Now is your opportunity! You should know enough to be able to read and understand some simple C# code, even if you still struggle to make modifications to a large application. Ask around for some suitable code to read. Perhaps try to find a known bug or requested feature, and have a go at making suitable changes to the code.
If you’re not yet confident enough to do this “for real”, there’s no harm in trying it “for practice” – just don’t commit the code to your source control and your tentative changes will never go live. This is a great opportunity not just to practice C#, but to get familiar with the particular applications you’re going to be working with. After you’ve been on the Bootcamp, you will hopefully be ready to take the next steps and start making a more substantial contribution to the projects you’re working on.
Good luck, and see you at the Bootcamp!