#5 Ref and Out Parameters

int NormalVaribale = 1;
 int referencevariable = 1;
 int outvaraibale = 1;

 referencemethod(ref referencevariable);
 outmethod(out outvaraibale);
 Console.WriteLine("Normal Variable"+NormalVaribale);
 Console.WriteLine("(REF)Reference Variable"+referencevariable);
 Console.WriteLine("(out) Out Varaible"+outvaraibale);

ref :Value must be Initialized before it is passed to the method. Reference is being passed to the method,so the value changed will get reflected./*It has got Nothing to do with value type and reference type both of these can use ref*/

out:Value need not be Assigned,but has to be defined before the method exists.

Note:Even though you have initialized before passing to method,you got to assign value before the method exists.


#4 Static Constructors

1.Static Constructors cannot have Access Modifiers  or have parameters.

2.They are initialized before  any static members are referenced.They are the First One to get Initialized.

3.A non static class can have static constructor.

class Test
static Test() //cannont have access modifier
Console.WriteLine("Hello World");





#3 Decorator Pattern

When to Use Decorator Pattern?

Add New Responsibility(functionality) to the class,without breaking the existing functionality.


1.Component as abstract class/Interface.

2.Concrete Components Implementing the Components.

3.Decorator as abstract class/Interface with Component as member initialized via constructor.

4.Concrete Decorator Implements Decorator.

Functionality are added at runtime,Hard to debug(Since object implements both Concrete Component and Concrete Decorator).

 Source Code:https://github.com/rangesh-/Design-Patterns/tree/master/Design%20Patterns/Decorartor%20Pattern