Skip to content

Commit c60dce6

Browse files
committed
Primary constructors
1 parent 7848786 commit c60dce6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>12</LangVersion>
9+
</PropertyGroup>
10+
11+
</Project>

PrimaryConstructors/Program.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
3+
Primary constructors
4+
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors#primary-constructors
5+
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-12.0/primary-constructors
6+
*/
7+
var emp01 = new Employee01();
8+
var emp02 = new Employee02(TimeSpan.Zero, TimeSpan.Zero);
9+
var emp03 = new Employee03(TimeSpan.Zero, TimeSpan.Zero);
10+
var emp04 = new Employee03();
11+
12+
class Employee01
13+
{
14+
15+
}
16+
17+
class Employee02
18+
{
19+
private TimeSpan _startTime;
20+
private TimeSpan _stopTime;
21+
public Employee02(TimeSpan startTime, TimeSpan stopTime)
22+
{
23+
_startTime = startTime;
24+
_stopTime = stopTime;
25+
}
26+
}
27+
28+
class Employee03(TimeSpan startTime, TimeSpan stopTime)
29+
{
30+
public Employee03(): this(new TimeSpan(0,0,0), new TimeSpan(0,0,0))
31+
{
32+
33+
}
34+
35+
public TimeSpan GetStartTime()
36+
{
37+
return startTime;
38+
}
39+
}

0 commit comments

Comments
 (0)