Close

Visual Studio

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

c# – The Interface

We previously came across the concept of inheritance, which is where a child class (implicitly) inherits the properties and methods from it’s parent class. However what if you don’t want a class to inherit methods and properties, but we do want class to have certain members (properties and methods) with […]

Read More

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 […]

Read More

c# – Abstract Classes

When you organise your code into parent and child classes (in order to fully utilize the concept of inheritance in order to cut down code duplication), you may end up with parent classes, that are just there for the purpose of holding base-class code. The class itself isn’t needed for […]

Read More

c# – Instantiate an object and set it’s Properties simultaneously (using the Initialization approach)

  1st Approach: Using Initialization Here we use properties (as demonstrated in the previous), but this time we set all the properties in one go, by writing them as part of the object’s actual declaration, using curly-bracket syntax: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class […]

Read More