项目中的全局变量。 [英] Global variables in a project.

查看:96
本文介绍了项目中的全局变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在项目中创建一个可供所有

类/表单访问的类实例?我已经有了一个启动模块,我想是把它放在那里,然后通过那里访问它。


我需要像db连接这样的东西,安全经理,一般数据库

功能,.....


任何帮助将不胜感激.....


UJ。

How do I create an instance of a class that is accessible to all
classes/forms in my project? I already have a startup module and I was
thinking putting stuff in there and then accessing it through there.

I need it for things like db connections, security manager, general db
functions, .....

Any help would be appreciated.....

UJ.

推荐答案

您可以创建一个使用Singleton模式的类。

类似于.. 。


公共类DBCentral


私有_theInstance为DBCentral


公共只读共享属性TheInstance( )作为DBCentral

get()

如果_theInstance什么都没有那么

_theInstance = new DBCentral()

end如果

返回_theInstance

结束获得

结束财产


结束班


我没有检查确切的语法,但你得到了图片....


-

鲍勃鲍威尔[ MVP]

Visual C#, System.Drawing


在Windows窗体中查找优秀的Windows窗体文章提示和技巧
http://www.bobpowell.net/tipstricks.htm

用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm


所有新文章都提供C#和VB.NET中的代码。

订阅所提供的RSS提要,绝不会错过任何新文章。

" UJ" < UJ@nowhere.com>在消息中写道

新闻:O9 ************** @ TK2MSFTNGP12.phx.gbl ...
You can create a class that uses the Singleton Pattern.
Something like...

public class DBCentral

private _theInstance as DBCentral

public readonly shared property TheInstance() as DBCentral
get()
if _theInstance is nothing then
_theInstance=new DBCentral()
end if
return _theInstance
end get
end property

end class

I didn''t check the exact syntax but you get the picture....

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"UJ" <UJ@nowhere.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
如何创建一个我的项目中所有类/表单都可以访问的类的实例?我已经有了一个启动模块,我正在考虑把东西放在那里,然后通过那里访问它。

我需要它用于数据库连接,安全管理器,通用数据库
功能,.....

任何帮助将不胜感激.....

UJ。
How do I create an instance of a class that is accessible to all
classes/forms in my project? I already have a startup module and I was
thinking putting stuff in there and then accessing it through there.

I need it for things like db connections, security manager, general db
functions, .....

Any help would be appreciated.....

UJ.



http://msdn.microsoft.com/architecture


chanmm


" UJ" < UJ@nowhere.com>在消息中写道

新闻:O9 ************** @ TK2MSFTNGP12.phx.gbl ...
http://msdn.microsoft.com/architecture

chanmm

"UJ" <UJ@nowhere.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
如何创建一个我的项目中所有类/表单都可以访问的类的实例?我已经有了一个启动模块,我正在考虑把东西放在那里,然后通过那里访问它。

我需要它用于数据库连接,安全管理器,通用数据库
功能,.....

任何帮助将不胜感激.....

UJ。
How do I create an instance of a class that is accessible to all
classes/forms in my project? I already have a startup module and I was
thinking putting stuff in there and then accessing it through there.

I need it for things like db connections, security manager, general db
functions, .....

Any help would be appreciated.....

UJ.



Chanmm,


你能指出我正确的方向吗?这是一般架构

页面。我没有看到全局的特定内容。


UJ。


" chanmmn" < CH ***** @ hotmail.com>在消息中写道

news:Og ************** @ TK2MSFTNGP12.phx.gbl ...
Chanmm,

Can you point me in the correct direction? This is a general architecture
page. I don''t see anything specific to globals.

UJ.

"chanmmn" <ch*****@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
http://msdn.microsoft.com/architecture

chanmm
UJ < UJ@nowhere.com>在消息中写道
新闻:O9 ************** @ TK2MSFTNGP12.phx.gbl ...
http://msdn.microsoft.com/architecture

chanmm

"UJ" <UJ@nowhere.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
如何创建类的实例我的项目中的所有类/表格都可以访问?我已经有了一个启动模块,我正在考虑把东西放在那里,然后通过那里访问它。

我需要它用于数据库连接,安全管理器,通用数据库
功能,.....

任何帮助将不胜感激.....

UJ。
How do I create an instance of a class that is accessible to all
classes/forms in my project? I already have a startup module and I was
thinking putting stuff in there and then accessing it through there.

I need it for things like db connections, security manager, general db
functions, .....

Any help would be appreciated.....

UJ.




这篇关于项目中的全局变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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