forked from ahotko/c-sharp-code-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstructorChainingSample.cs
31 lines (29 loc) · 1.14 KB
/
ConstructorChainingSample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
namespace CodeSamples.Classes
{
public class SampleClass
{
public SampleClass() : this(0) { Console.WriteLine("Default Constructor"); }
public SampleClass(int param) : this(0, "string param") { Console.WriteLine("Constructor with one parameter"); }
public SampleClass(int paramInt, string paramStr) { Console.WriteLine("Constructor with two parameters"); }
}
public class ConstructorChainingSample : SampleExecute
{
public override void Execute()
{
Title("ConstructorChainingSampleExecute");
Section("Creating class by calling constructor with no params");
SampleClass classNoParams = new SampleClass();
LineBreak();
//
Section("Creating class by calling constructor with 1 params");
SampleClass classOneParam = new SampleClass(1);
LineBreak();
//
Section("Creating class by calling constructor with 2 params");
SampleClass classTwoParams = new SampleClass(3, "Yo! This is a story all about how...");
//
Finish();
}
}
}