-
Notifications
You must be signed in to change notification settings - Fork 18
/
Program.cs
51 lines (39 loc) · 980 Bytes
/
Program.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
namespace Construction;
class Program
{
// This example runs constructors for their side effects, so warning
// CA1806 (which tells us we've constructed an object but not used it)
// is unhelpful here.
#pragma warning disable CA1806
static void Main()
{
new Example37.DerivedNoDefaultCtor(42);
Console.WriteLine();
new Example38.DerivedCallingBaseCtor();
Console.WriteLine();
new DerivedInit();
}
}
public class BaseInit
{
protected static int Init(string message)
{
Console.WriteLine(message);
return 1;
}
private int b1 = Init("Base field b1");
public BaseInit()
{
Init("Base constructor");
}
private int b2 = Init("Base field b2");
}
public class DerivedInit : BaseInit
{
private int d1 = Init("Derived field d1");
public DerivedInit()
{
Init("Derived constructor");
}
private int d2 = Init("Derived field d2");
}