static imports in c#

后端 未结 4 721
南方客
南方客 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:48

    Time marches on... it looks like C# might get static imports in the next version, see http://msdn.microsoft.com/en-us/magazine/dn683793.aspx for a preview.

    using System;
    using System.Console; // using the Console class here
    
    public class Program
    {
        public static void Main()
        {
            // Console.WriteLine is called here
            WriteLine("Hello world!");
        }
    }
    

    The official documentation for the 'Roslyn' C# compiler lists the feature as 'done'

提交回复
热议问题