How to “import” a static class in C#?

后端 未结 9 1418
挽巷
挽巷 2020-12-28 19:08

I have created a public static class utils.cs I want to use it in other classes without prefixing method with utils, what\'s the syntax to do this ?

9条回答
  •  独厮守ぢ
    2020-12-28 19:17

    As a minimum, you have to specify at least the class name. All the using directive does is allow you to leave off the namespace. You can also use the using directive to specify an alias Instead of the entire namespace.class name, but then you have to use the alias...

    using MyClassName = Namespace.MySubNS.OtherNameSpace.OriginalClassname;
    
    MyClassName X = new MyClassName(); 
    

提交回复
热议问题