Close

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[] args) { // here we […]

Read More

c# – Generics: Stack

Stacks are practically the same thing as Queues, but works on the basis of last-in, first-out. Here is the stack’s reference page: http://msdn.microsoft.com/en-us/library/3278tedw(v=vs.110).aspx It basically works in the opposite order of how a queue works. Here’s an example: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Queue { class Program { […]

Read More

c# – Generics: Queue

Queues are like lists, but works on the basis of first-in, first-out, here’s an example: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Queue { class Program { static void Main(string[] args) { // here we create an empty queue that we define to only hold // integers. Queue<int=> MyQueue = […]

Read More

c# – Generics: Lists

Arrays have a big limitation is that you cant extend the array to hold more than the number items it was originally defined to hold. As a result a lot of people uses “lists” as an alternative. You can find the lists class in the following namespace: System.Collections.Generic Here is the link for the “generic” […]

Read More

c# – Arrays

Arrays are used to store a a group of items as a collection: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Arrays { class Program { static void Main(string[] args) { // Here we are creating an array called "vowels", that can house up to 5 items. string[] vowels = new […]

Read More

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