模块VB.Net中的命名空间(Namespace in module VB.Net)
我想知道是否有任何方法可以将命名空间(或类似的东西)放入模块中,仅用于代码排序,如下所示:
Public Module1 Namespace N1 (or whatever) Public N1_1 as integer = 45 End Namespace Namespace N2 (or whatever) Public N2_1 as integer = 28 End Namespace End Module
那么我可以这样做:
Module1.N1.N1_1
谢谢!
编辑:值必须能够更改,所以我不能使用枚举
I would like to know if there is any way to make a namespace (or something like that) into a module, is just for code sorting, something like this:
Public Module1 Namespace N1 (or whatever) Public N1_1 as integer = 45 End Namespace Namespace N2 (or whatever) Public N2_1 as integer = 28 End Namespace End Module
So then I can do:
Module1.N1.N1_1
Thanks!
Edit: values must be able to be changed so I can't use Enum
原文:https://stackoverflow.com/questions/26028126
更新时间:2022-12-04 13:12
最满意答案
您需要将多个类包装到命名空间中。
那么您的类只有共享成员/属性。
像这样的东西:
Namespace Module1 Class N1 (or whatever) Public Shared N1_1 as integer = 45 End Class Class N2 (or whatever) Public Shared N2_1 as integer = 28 End Class End Namespace
You need to wrap multiple classes into a namespace instead.
Your classes would then only have Shared members / properties.
Something like this:
Namespace Module1 Class N1 (or whatever) Public Shared N1_1 as integer = 45 End Class Class N2 (or whatever) Public Shared N2_1 as integer = 28 End Class End Namespace
相关问答
更多-
asp.net (vb.net)怎样调用Module文件?[2019-05-30]
直接去添加引用~然后去调用就可以了 -
vb.net那里下载[2022-12-02]
官方下载地址:http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express 此为:vb.net express版本,没有时间限制 -
vb.net 教程[2021-11-13]
http://msdn.microsoft.com/zh-cn/library/2x7h1hfk.aspx 微软官方MSDN是最权威的初学场所 -
模块VB.Net中的命名空间(Namespace in module VB.Net)[2022-12-04]
您需要将多个类包装到命名空间中。 那么您的类只有共享成员/属性。 像这样的东西: Namespace Module1 Class N1 (or whatever) Public Shared N1_1 as integer = 45 End Class Class N2 (or whatever) Public Shared N2_1 as integer = 28 End Class End Namespace You need ... -
它们被称为Class文件。 右键单击要添加类的解决方案或文件夹,然后选择“ Add new item然后从窗口中选择“ Class 。 They are called Class files. Right-click on your solution, or folder you wish to add the class and choose Add new item then from the window choose Class.
-
“Main()”是一个功能。 并且您声明了一个局部变量“sConnection”。 您的表格是另一个类。 类只能访问其成员,全局成员或全局静态成员(或某些朋友方案,如C ++)。 从“Main”中取出声明,在表单范围内声明或将其声明为全局变量,表单可以访问。 或者将您的连接字符串放在配置文件中并从中读取。 (在以后的时间点很容易配置。) The "Main()" is a function. And you declared a local variable "sConnection". Your Form ...
-
您可以在VB中运行powershell脚本,请查看以下链接 http://blogs.msdn.com/b/zainnab/archive/2008/07/26/calling-a-powershell-script-from-your-net-code.aspx 上面发布的链接将逐步指导您如何完成此任务。 查看与您相关的问题: 在.NET Windows应用程序中运行powershell脚本 以下文章在C#中,但应该可以帮助您更好地理解这个概念: http://www.codeproject.com/Ar ...
-
如果我理解正确的是什么,则通过自动将文件VbMyTemplateText.vb到每个编译中来添加My命名空间。 为了使它实际生成一些东西,必须正确设置预处理器符号_MYTYPE (在控制台应用程序的情况下为"Console" )。 要使这项工作,你还需要引用System.dll ,但之后一切正常: Imports System.CodeDom.Compiler Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.VisualBasic ...
-
VB.Net模块行为(VB.Net module behavior)[2022-06-25]
Module在技术上并不意味着静态类。 VB.net中的静态(关于函数)是Shared ,并且没有Shared Class 。 我认为你想要的是一个带有静态/共享函数的密封/抽象/不可继承的类(你可以在没有父类实例的情况下调用函数,但是你仍然需要引用父类。调用函数)。 如果是这种情况,那么执行类似以下的操作: Public NotInheritable Class HelperA Public Shared Function FunctionA() as Boolean Return ... -
将VB.net模块转换为C#(convert VB.net Module to C#)[2021-07-14]
您可以将常量放在public static class如下所示: public static class MyConnectionStringConstants { public const string strDatabase = "****"; public const string strUserID = "****"; public const string strPssWd = "****"; } 要使用它,您需要像这样引用常量: string strAccessConn ...