全局变量该如何定义,在哪定义比较好?
我有类似如下的结构数组
struct STRUFILE
{
public int monitor_id;
public string device_name;
...
}
STRUFILE[] G_FILEINFO;
在程序启动时会读数据库,给结构数组赋值
由于程序不少FROM和线程都会用到,所以我该在那定义这个全局变量
是在主Form的CS文件还是在Program.cs或是重新建一个文件,请教!
我有类似如下的结构数组
struct STRUFILE
{
public int monitor_id;
public string device_name;
...
}
STRUFILE[] G_FILEINFO;
在程序启动时会读数据库,给结构数组赋值
由于程序不少FROM和线程都会用到,所以我该在那定义这个全局变量
是在主Form的CS文件还是在Program.cs或是重新建一个文件,请教!
解决方案 »
- c#的托盘图标怎样才能获取这个程序本身的exe图标啊?
- C#的WIN FORM程序,为什么断点后不能更改程序?
- 页面用vs2005自带的view in browser可以打开
- C#调用C写的DLL,DLL中的unsigned char*该转换成什么类型?在线等待
- 请问怎么把已经做好的winform生成为exe的执行文件呀???
- 安装部署中,默认安装路径问题
- 又是propertygrid!如何展开属性?
- 请问高手一个关于JMAIL的问题?
- 为什么插入语句总是把空值默认成零
- System.Net.Sockets.SocketException: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
- 查询结果返回并刷新
- 一组棘手的byte数组循环,求助
{
int static myint = 0;
string static mystring = string.Empty;
......
}
{
public struct STRUFILE
{
public int monitor_id;
public string device_name;
...
}
STRUFILE[] G_FILEINFO;
}
定义成 public static STRU_FILE[] strufile;
public class GlobalClass
{
public struct STRUFILE
{
public int monitor_id;
public string device_name;
...
}
public static STRUFILE[] G_FILEINFO;
}我在Form_Load的时候给这个结构数组赋值
GlobalVar.G_FILEINFO[0].monitor_id=10;
结果产生异常 产生一个NullReferenceException
"Object reference not set to an instance of an object."