Close

Visual Studio

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

2nd Approach – Using the “Constructor” Constructor is a special type of method that is present in all classes, even if you don’t explicitly define it in the class itself. Constructors are used for creating an instance of the object…. this basically means that whenever you declare a new instance […]

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

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"); […]

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

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

Read More