-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConstructorChainingSample.cs
51 lines (48 loc) · 2.2 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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();
// Output:
//
// ConstructorChainingSampleExecute
// ============================================================
// Creating class by calling constructor with no params
// ============================================================
// Constructor with two parameters
// Constructor with one parameter
// Default Constructor
// ============================================================
// Creating class by calling constructor with 1 params
// ============================================================
// Constructor with two parameters
// Constructor with one parameter
// ============================================================
// Creating class by calling constructor with 2 params
// ============================================================
// Constructor with two parameters
// ============================================================
}
}
}