Skip to content

Commit f9c94f0

Browse files
authored
Merge pull request #14 from devlights/csharp7-new-feature-more-expression-bodies
Add C# 7.0 Expression Body advanced example
2 parents 3d4c79b + 2733885 commit f9c94f0

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using TryCSharp.Common;
2+
3+
namespace TryCSharp.Samples.CSharp7
4+
{
5+
[Sample]
6+
public class MoreExpressionBodiedMembers : IExecutable
7+
{
8+
class Data
9+
{
10+
private string _value;
11+
12+
public Data(string val) => this.Value = val;
13+
14+
public string UpperCaseValue => this.Value.ToUpper();
15+
16+
// ReSharper disable once ConvertToAutoProperty
17+
public string Value
18+
{
19+
get => this._value;
20+
private set => this._value = value;
21+
}
22+
23+
public string ToLowerValue() => this.Value.ToLower();
24+
}
25+
26+
public void Execute()
27+
{
28+
// C# 6.0 にて Expression Body が導入されたが
29+
// C# 7.0 にて、新たに
30+
// - コンストラクタ
31+
// - read/write プロパティ
32+
// - ファイナライザ
33+
// でも利用できるようなった
34+
var data = new Data("hello world");
35+
Output.WriteLine($"{data.Value}-{data.UpperCaseValue}-{data.ToLowerValue()}");
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)