VB.NET导入类 [英] VB.NET Importing Classes

查看:117
本文介绍了VB.NET导入类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过一些代码,其中导入了 Class 而不是命名空间,使该类的所有静态成员/方法都可用。这是VB的一个功能吗?或者其他语言也可以这样做吗?

I've seen some code where a Class is imported, instead of a namespace, making all the static members/methods of that class available. Is this a feature of VB? Or do other languages do this as well?

TestClass.vb

TestClass.vb

public class TestClass
    public shared function Somefunc() as Boolean
        return true
    end function
end class

MainClass.vb

MainClass.vb

imports TestClass

public class MainClass
    public sub Main()
        Somefunc()
    end sub
end class

这些文件位于App_Code目录中。只是好奇,因为我以前从未想过这样做,也没有在任何地方读过它。

These files are in the App_Code directory. Just curious, because I've never thought of doing this before, nor have I read about it anywhere.

推荐答案

此功能的一个原因是模拟Visual Basic 6.0的GlobalMultiUse Option for Instancing。 Visual Basic 6.0无法跨DLL边界公开模块。而是将实例化属性设置为 GlobalMultiUse 。它主要用于实用程序类,如导出一系列数学函数的类。

One of the reasons this feature is in place is to emulate Visual Basic 6.0's GlobalMultiUse Option for Instancing. Visual Basic 6.0 doesn't have the ability to make modules public across a DLL boundary. Instead you set the instancing property to GlobalMultiUse. It is used mainly for utility classes like a class that export a series of math functions.

每次使用<$ c $调用类的子例程或函数时c> GlobalMultiUse Instancing ,Visual Basic 6.0在调用函数之前实例化一个类。

Every time you call a subroutine or function on a class with the GlobalMultiUse Instancing, Visual Basic 6.0 instantiates a class behind the scenes before calling the function.

可以滥用它来生成全局函数/具有所有优点和缺点的变量。

It can be abused to generate global functions/variables with all the advantages and disadvantages.

这篇关于VB.NET导入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆