Close

c# – The “this” keyword

Earlier we cam across the following: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Employee { public string Firstname { get; set; } //Note, the above line is the shorthand way of writing the following: // // private string firstname; // here we are defining a property called "firstname" // public […]

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 // wont recognise this a […]

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: // this is how to […]

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 ; Console.WriteLine("Are both true: " + […]

Read More

c# – Booleans

booleans are variables that hold true or false.   [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 ; Console.WriteLine("Are both true: […]

Read More