你可以做一个静态的变量public static Test ApplicationConfig =new Test();public class Test { public int ConfigInt{get;set;} public string Config1{get;set;} }不行吗?
using System; using System.Collections.Generic; using System.Text; using System.Net.Sockets; using System.IO; using System.Xml; using System.Data; namespace oaelf { public static class clsglo {
public static Socket clientSocket; //客户机SOCKET对像 public static string loginFlag; //登陆标志 public static TcpClient tcpcl = new TcpClient(); //客户TCP联接 public static string strname; //用户姓名 public static string strID; //用户ID public static string strPws; //用户密码 public static string strinoaURL; //内网OA地址 public static string stroutoaURL; //外网OA地址 public static string strinftpURL; //内网FTP地址 public static string stroutftpURL; //外网FTP地址 public static string strftpuser; //FTP用户名 public static string strftppws; //FTP密码 public static IList<FormMSG> m_List = new List<FormMSG>(); //窗体列表 /// <summary> /// 将指定datatable转换为其等效的xml流形式。 /// </summary> /// <param name="table">datatable对象</param> /// <returns></returns> public static string toxmlstring(DataTable table) { if (table == null) { return null; } StringBuilder content = new StringBuilder(); StringWriter writer = new StringWriter(content); XmlTextWriter xmlwriter = new XmlTextWriter(writer); try { DataSet ds = new DataSet(); ds.Tables.Add(table.Copy()); ds.WriteXml(xmlwriter); return content.ToString(); } finally { writer.Close(); xmlwriter.Close(); } } /// <summary> /// 将指定的xml流转换为其等效的dataset对象。 /// </summary> /// <param name="xmlstream">xml流</param> /// <returns></returns> public static DataSet todataset(string xmlstream) { if (xmlstream == null || xmlstream.Trim().Length == 0) { return null; } StringReader reader = new StringReader(xmlstream); XmlTextReader xmlreader = new XmlTextReader(reader); try { DataSet ds = new DataSet(); ds.ReadXml(xmlreader); return ds; } finally { reader.Close(); xmlreader.Close(); } } } }
{ //******************************************************************
//*Hashtable用于存放全局变量,由key和value成对实现。
//******************************************************************
private static Hashtable table = new Hashtable(); //******************************************************************
//*由于是私有构造函数,不能由new产生实例,所以只有一个实例,
//*保证了该类在程序中是唯一的。
//******************************************************************
创建一个 globalVariable的.CS 的类文件
private globalVariable()
{} public static object GetValue(object akey)
{
return table[akey];
}
public static void SetValue(object akey, object avalue)
{
table[akey] = avalue;
}
public static void Remove(object akey)
{
table.Remove(akey);
}
}把你要存的对象放进去就行了
{ //******************************************************************
//*Hashtable用于存放全局变量,由key和value成对实现。
//******************************************************************
private static Hashtable table = new Hashtable(); //******************************************************************
//*由于是私有构造函数,不能由new产生实例,所以只有一个实例,
//*保证了该类在程序中是唯一的。
//******************************************************************
private globalVariable()
{} public static object GetValue(object akey)
{
return table[akey];
}
public static void SetValue(object akey, object avalue)
{
table[akey] = avalue;
}
public static void Remove(object akey)
{
table.Remove(akey);
}
}
{
public int ConfigInt{get;set;}
public string Config1{get;set;}
}不行吗?
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Xml;
using System.Data;
namespace oaelf
{
public static class clsglo
{
public static Socket clientSocket; //客户机SOCKET对像
public static string loginFlag; //登陆标志
public static TcpClient tcpcl = new TcpClient(); //客户TCP联接
public static string strname; //用户姓名
public static string strID; //用户ID
public static string strPws; //用户密码
public static string strinoaURL; //内网OA地址
public static string stroutoaURL; //外网OA地址
public static string strinftpURL; //内网FTP地址
public static string stroutftpURL; //外网FTP地址
public static string strftpuser; //FTP用户名
public static string strftppws; //FTP密码 public static IList<FormMSG> m_List = new List<FormMSG>(); //窗体列表 /// <summary>
/// 将指定datatable转换为其等效的xml流形式。
/// </summary>
/// <param name="table">datatable对象</param>
/// <returns></returns>
public static string toxmlstring(DataTable table)
{
if (table == null)
{
return null;
}
StringBuilder content = new StringBuilder();
StringWriter writer = new StringWriter(content);
XmlTextWriter xmlwriter = new XmlTextWriter(writer); try
{ DataSet ds = new DataSet();
ds.Tables.Add(table.Copy());
ds.WriteXml(xmlwriter); return content.ToString();
}
finally
{
writer.Close();
xmlwriter.Close();
}
} /// <summary>
/// 将指定的xml流转换为其等效的dataset对象。
/// </summary>
/// <param name="xmlstream">xml流</param>
/// <returns></returns>
public static DataSet todataset(string xmlstream)
{
if (xmlstream == null || xmlstream.Trim().Length == 0)
{
return null;
} StringReader reader = new StringReader(xmlstream);
XmlTextReader xmlreader = new XmlTextReader(reader);
try
{
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
return ds;
}
finally
{
reader.Close();
xmlreader.Close();
}
}
}
}
高手们帮小弟看看, 我急啊