在.NET中,有没有全局变量的概念? [英] In .NET, is there a concept of global variables?

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

问题描述

在VB6我们这是在模块文件中声明的全局变量。

In VB6 we have global variables which are declared in module files.

在.NET中,我们是否有这样一个概念?抑或是通过会话变量替换之类的东西类的静态常量变量这可以作为全球数据?

In .NET, do we have such a concept? Or is it replaced by session variables and things like static constant variables of class which can be used as global data?

推荐答案

在VB.NET,你可以添加模块文件。在这个模块文件,你必须使用公共声明变量和/或功能。但是,这仅仅是在VB.NET

In VB.NET, you can add module file. In that module file, you had to declare variable and/or functions with Public. But this is only in VB.NET

例如,模块文件会是这样

Example, module file would be like this

Module UserDetails

Public SqlCon as SqlConnection
Public DataSet as DataSet
Public dataAdaptr as SqlDataAdapter

End Module

在上面的例子中,我使用SQL连接,数据集,数据适配器免遭任何形式,类和模块。

In above example, i am using sql connection, data set, data adapter from any form, class and module.

这个例子被用在我的项目了。您可以在Asp.net项目中也用这个。

This example is being used in my projects already. You can use this in your Asp.net projects too.

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

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