Close

csharp

c# – Hello World

Here we are going to first show you a simple “hello world” program in the form of an exe file. When you double-click on the exe file, all that will happen is that a console terminal will open a display the message “hello world”, like this:   Step 1 -Write […]

Read More

c# – Embed variables in a string using the substition technique

Previously in the boolean chapter we saw: [csharp] using System; class BooleanDemo { static void Main() { bool myFirstBoolean = 3 + 2 == 5; Console.WriteLine(myFirstBoolean.ToString()); bool mySecondBoolean = 3 + 2 => 5; Console.WriteLine(mySecondBoolean.ToString()); // Here we use the ‘and’, "&&" operator bool BothAreTrue = myFirstBoolean && mySecondBoolean ; […]

Read More

c# – Generics: Dictionary (aka hashtable)

In c#, dictionaries are the same thing as hashtables. Dictonaries are a bit like arrays where you can customise the default index numbers to something more meaningful, here’s an example: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Dictionary { class Program { static void Main(string[] […]

Read More

c# – Switch statements (aka case statements)

Here is a quick switch statement demo: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SwitchStatementDemo { class Program { static void Main(string[] args) { Console.Write("enter a number: "); //the parse converts the input into an integer. int input = int.Parse(Console.ReadLine()); switch (input) { case 1: […]

Read More

c# – Using the “Null” object

Sometimes a method will ask for an input parameter, but that input parameter is optional. In these situation you can still trigger the method, without passing an input parameter, and instead pass in a “null” object in it’s place: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; […]

Read More

c# – Create a variable that can only hold a fixed set of values (aka an Enum Constant)

A enum constant is a special kind of variable that can only take a set number of values, e.g.: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp { class EnumConstantDemo { // notice that you have to place this outside the method, othewise the method […]

Read More

c# – Intro to Exceptions

Sometimes you might have a block of “dangerous code” in your program. These are code that could fail. When these blocks of “dangerous codes” fail, it will stop the program straight, and won’t attempt to carry on any further, and instead it will just output an error message. However sometimes […]

Read More