We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 31797c9 commit af56395Copy full SHA for af56395
1 file changed
TryCSharp.Samples/CSharp7/LocalMethods.cs
@@ -0,0 +1,34 @@
1
+using System;
2
+using TryCSharp.Common;
3
+
4
+namespace TryCSharp.Samples.CSharp7
5
+{
6
+ [Sample]
7
+ public class LocalMethods : IExecutable
8
+ {
9
+ public void Execute()
10
11
+ // C# 7.0 にて ローカルメソッド が導入された
12
+ // ローカルメソッド は、メソッドの中でローカルに利用できるメソッドを定義する機能
13
+ // 元々 Action や Func を用いても同様のことが出来たが、それが基本機能となった
14
15
+ int Sum(int x, int y) => x + y;
16
17
+ Output.WriteLine(Sum(1, 2));
18
+ Output.WriteLine(Sum(100, 1_000_00));
19
20
+ // delegate として利用することも可能
21
+ Func<int, int, int> f = Sum;
22
+ Output.WriteLine(f(100, 1_000_00));
23
24
+ // delegate として渡すことも可能
25
+ ExecLocalMethods(f);
26
+ ExecLocalMethods(Sum);
27
+ }
28
29
+ private void ExecLocalMethods(Func<int, int, int> f)
30
31
+ Output.WriteLine(f(9, 1));
32
33
34
+}
0 commit comments