Close

c# – An intro to Arrays and Generics

Here are some terminologies: Arrays: This is a object variable, that is designed to store a collection of object-variable. Each object variable is stored in numbered containers (i.e. they are indexed), with the first container starting at number 0. Generics: these are like arrays, but they can only store builtin c# variables, i.e. variables that […]

Read More

c# – Random Number Generator

Here’s a quick a simple class for creating a a series of random numbers, by creating an instance of the “Random” class, and applying this class’s next() method: http://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx Here is the code: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RandomNumberGenerator { class Program { static void Main(string[] args) { […]

Read More

c# – Over-riding generic methods

Child classes can inherit methods from it’s parent class, in the same way that it inherits properties. Here is an example of the Orange class inheriting the “SomeInfo” method, which have been originally defined in the Item class:   [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InheritenceInAction { class Program […]

Read More

c# – Creating objects from generic parent classes

In the previous unit we came across: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InheritenceInAction { class Program { static void Main(string[] args) { // Here we create an object using the orange class Orange AnOrange = new Orange(1.25, 45, "Spain", "25-01-2015", "sweet", true, "clementine"); string ContainsSeedsSentence; if (AnOrange.ContainsSeeds) { […]

Read More

c# – Inheritence in Action

Lets say we have a supermarket and it sells a different types of fruits, then you could create a class for each type of fruit: The above will output: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InheritenceInAction { class Program { static void Main(string[] args) { // Here we create […]

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 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