File tree Expand file tree Collapse file tree
TryCSharp.Samples/CSharp7 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments