如何在不声明对象的情况下使用类
我正在尝试在 VB .NET 中开发一个类,以便管理存储在数据库中且可由用户编辑的语言全球化。
我需要的是知道我需要声明什么样的类才能在不声明新对象的情况下使用它。例如My.Settings的使用方式。
目标之一是在某些项目中,开发人员导入引用,然后直接访问属性。例如:My.CustomLanguage.GetWord("Hello") 而不声明对象。
这可能吗?如果是的话,最好的解决方法是什么?
谢谢。
I'm trying to develop a class in VB .NET in order to manage a language globalization stored in a database and editable by the user.
What I need is to know what kind of class I need to declare in order to use it without declaring a new object. For example, the way My.Settings is used.
One of the goals is that in some project the developer imports the reference and after that access directly to a property. For example: My.CustomLanguage.GetWord("Hello") without declaring objects.
Is this possible? And if it's what is the best way to aproach it?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将需要访问的每个属性或方法声明为静态,在 VB 中为“共享”
You can declare every property or method that you need to access as static, in VB, "Shared"
我认为你想要一个只有静态方法和字段的类
I think you want a class with only static methods and fields
你需要的是一个单例类。
声明您的类后,添加与您的类具有相同类型的公共静态属性。
这将有所帮助: http://msdn.microsoft.com/en-us/library /ff650316.aspx
What you need is a singleton class.
After declaring your class add a public static property having the same type as your class.
This will help: http://msdn.microsoft.com/en-us/library/ff650316.aspx
首先创建类,因为
您可以通过表单中的代码直接调用此类
First Make Class as
you can call this class direct by this code in your form