是否可以将静态类作为名称空间导入以调用其方法,而无需在C#中指定类名称? [英] Can I import a static class as a namespace to call its methods without specifying the class name in C#?
问题描述
我大量使用一种特定静态类的成员函数.每次调用它的方法时都指定类名看起来很麻烦...
I make extensive use of member functions of one specific static class. Specifying the class name every time I call it's methods looks nasty...
是否可以在不指定类名C#的情况下将静态类作为名称空间导入以调用其方法?
Can I import a static class as a namespace to call its methods without specifying the class name C#?
推荐答案
如果您的意思是导入它,使其方法是全局的,则不可以.
If you mean import it such that it's methods are global, no.
您可能想看看扩展方法.它们是静态方法,当导入其类的名称空间时,它们将作为实例方法显示在其第一个参数的类型上.在此处查看更多信息: http://msdn.microsoft.com/en-us/library/bb383977.aspx
You might want to look at extension methods though. They are static methods that, when their class's namespace is imported, show up as instance methods on the type of their first argument. See more here: http://msdn.microsoft.com/en-us/library/bb383977.aspx
这篇关于是否可以将静态类作为名称空间导入以调用其方法,而无需在C#中指定类名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!