首页 > Windows开发 > 详细

C#中如何定义全局变量及在各窗体中使用全局变量

时间:2016-12-01 22:27:30      阅读:331      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace NewTest
{
	public class PublicValue
	{
		public static string FileName;
		public static int[] aa;
	}
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void MainFormLoad(object sender, EventArgs e)
		{
			this.Width=Screen.PrimaryScreen.WorkingArea.Width;
			this.Height =Screen.PrimaryScreen.WorkingArea.Height;
			this.Left =Screen.PrimaryScreen.WorkingArea.Left;			
			this.Top =Screen.PrimaryScreen.WorkingArea.Top;			
		}
		
		void Button1Click(object sender, EventArgs e)
		{			
			PublicValue.aa=new int[10];
			PublicValue.aa[0]=10;
			PublicValue.FileName="dfjlkjkldfsjl";
		}
	}
}

以上定义的publicValue类,其中的变量可以在同一个命名空间中使用,包括在子窗体或非子窗口中调用。

C#中如何定义全局变量及在各窗体中使用全局变量

原文:http://www.cnblogs.com/China3S/p/6123454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!