File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using TryCSharp . Common ;
2+
3+ // using static の利用
4+ // これにより、Consoleクラスのstaticメソッドをクラス名修飾なしで利用出来る
5+ // python の from xxx import xxx と同じような感じ。
6+ using static System . Console ;
7+
8+ namespace TryCSharp . Samples . CSharp6
9+ {
10+ using static MyStaticClass ;
11+
12+ [ Sample ]
13+ public class UsingStaticSamples01 : IExecutable
14+ {
15+ public void Execute ( )
16+ {
17+ // Consoleクラスに対して、using static しているので
18+ // メソッド呼び出しにConsoleを付けなくても呼べる。
19+ WriteLine ( "hello world" ) ;
20+
21+ // 当然、自前のクラスに対しても using static 出来る
22+ MyStaticMethod ( "hello world" ) ;
23+ }
24+ }
25+
26+ public static class MyStaticClass
27+ {
28+ public static void MyStaticMethod ( string message )
29+ {
30+ Output . WriteLine ( message ) ;
31+ }
32+ }
33+ }
Original file line number Diff line number Diff line change 146146 <Compile Include =" Commons\Extensions\StringExtensions.cs" />
147147 <Compile Include =" CSharp6\AutoPropSamples01.cs" />
148148 <Compile Include =" CSharp6\ExpressionBodySamples01.cs" />
149+ <Compile Include =" CSharp6\UsingStaticSamples01.cs" />
149150 <Compile Include =" Dummy.cs" />
150151 <Compile Include =" Helpers\CompareResultHelper.cs" />
151152 <Compile Include =" IO\GetInvalidPathCharsAndGetInvalidFileNameCharsSamples01.cs" />
You can’t perform that action at this time.
0 commit comments