static imports in c#

后端 未结 4 722
南方客
南方客 2020-12-15 15:22

Does C# has feature like Java\'s static imports?

so instead of writing code like

FileHelper.ExtractSimpleFileName(file)

I could wr

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 15:25

    C# 6.0 under Roslyn Platform supports Static import. It requires statement like:

    using static System.Console;
    

    so the code might look like:

    using static System.Console;
    namespace TestApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                WriteLine("My test message");
            }
        }
    }
    

    The earlier planned version for C# 6.0 had static import without static keyword.

    For other new features in C# 6.0 see: New Language Features in C# 6

提交回复
热议问题