Skip to content

Instantly share code, notes, and snippets.

View dnasca's full-sized avatar

Derrik dnasca

View GitHub Profile
using System;
/* Explicit Interface Implementation
*
* When you are explicitly implementing an interface member, you are not allowed to use an access modifier
*
* You have to use the interface name dot MethodName, ex. IInterface1.InterfaceMethod();
*
* When a class explicitly implements an interface member, the interface member can no longer be accessed through a
* class reference variable, but instead can only be accessed via the interface reference variable
@dnasca
dnasca / GetterSetterMethods.cs
Created March 17, 2015 06:28
This is redundant with get; and set; methods built-in, but this is a good way to see whats happening by doing it ourselves!
using System;
/* Not all programming languages use Properties
*
* Getter and Setter methods are used to encapsulate and protect fields
*
*/
public class Student
using System;
using System.IO;
/* Inner Exception Notes
*
* The InnerException property returns the Exception instance that caused the current exception
*
* To retain the original exception, pass it as a parameter to the constructor of the current exception
*
@dnasca
dnasca / InterfaceBasics.cs
Created March 17, 2015 06:30
Interface Basics
using System;
/* //Interface Basics//
*
* Interfaces can contain properties, methods, delegates or events but ONLY the declarations. NOT implementations.
*
* Interface members are public by default and DO NOT allow explicit access modifiers
*
* Interfaces CANNOT contain fields
*
@dnasca
dnasca / LAMBDAinsteadofDelegateUsage.cs
Last active August 29, 2015 14:17
the goal for this Employee class is to have no hard coded logic within the class
using System;
using System.Collections.Generic;
//the goal for this Employee class is to have no hard coded logic within the class. We can accomplish this using a delegate and a single LAMBDA expression on Line 42
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public int CurrentSalary { get; set; }
public int YearsExperience { get; set; }
using System;
/* Method Overriding and Method Hiding
*
* In method overriding, a base class reference variable pointing to a child object will invoke the overriden method in the child class
*
* In method hiding, a base class reference variable pointing to a child class object will invoke the hidden method in the base class
*
*/
using System;
/* Multicast Delegates
*
* A multicast delegate is a delegate that has a reference to more than one function.
* When you invoke a multicast delegate, all of the functions the delegate is pointing to are invoked.
*
* There are 2 approaches to create a multicast delegate (multiple instances, or the same instance)
* 1. + or += to register a method with the delegate (SEE APPROACH ONE)
* 2. - or -= to un-register a method with a delegate (SEE APPROACH TWO)
using System;
interface IA
{
void AMethod(); //declare method
//method implemented in class A
}
public class A : IA //inherit from interface A
{
using System;
public class ParentClass
{
public ParentClass() //parameterless constructor, this will be overloaded if the ParentClass constructor is called with a string argument
{
Console.WriteLine("ParentClass Constructor called");
}
public ParentClass(string Message) //method overloads parameterless ParentClass constructor if ParentClass constructor is called with a string argument
@dnasca
dnasca / Polymorphism with virtual and override.cs
Created March 17, 2015 06:38
Polymorphism with virtual and override
using System;
/* Polymorphism with virtual and override
*
* Base class reference variables can point to a child class object
*
* !@!@ Polymorphism enables us to invoke derived class methods using a base class reference variable at RUN-TIME !@!@
*/
public class Employee