Static 静态成员的说明

博主进行测试后发现,除了Application可用于全局性变量应用,static也能实现。文中给出了BaseConfig类中使用static定义多个变量的示例,还展示了密码验证、用户信息处理及在线信息管理等相关代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在做了一下测试,以前在网上只是看到过,没有测试,一直一来就觉得全局性变量的应用只有Application,其时static也可以用到!例如:

public class BaseConfig
 {
  public static string system_reged = "非法用户";

  public static bool log_system = true;
  public static bool log_error = true;
  public static int public_pbc = 5;
  public static int public_title = 2;
  public static int public_html = 10;
  public static int public_pbc_imgheight = 100;
  public static int public_pbc_imgwidth = 200;
  public static int public_fightgrade = 100;
  public static ArrayList public_roomlist = new ArrayList();
  public static Hashtable public_onlineinfo = new Hashtable();
  public static int public_online = 0;
  public static int public_inchat = 0;
  public static string[] public_goldmax = new string[4];
  public static int[] public_t1 = new int[4];
  public static int[] public_t2 = new int[4];
  public static int[] public_t3 = new int[4];
  public static int[] public_t4 = new int[4];
  public static string public_adminclass = "六扇门";
  public static bool public_adminfree = true;
  public static ArrayList public_randomhappen = new ArrayList();
  public static string public_streettype;
  public static DataTable public_street;
  public static x.CheckUse public_song;
  public static x.CheckUse public_webicq;
  public static x.CheckUse public_fly;
  public static x.CheckUse public_bet;
  public static int public_question = 6;
  public static DataTable public_horseinfo;
  public static DataTable public_shopthing;
  public static string public_shoptype;
  public static int public_horsespan = 180;
  public static Hashtable public_horselist = new Hashtable();
  public static int public_horseID = 1;
  public static Hashtable public_questionlist = new Hashtable();
  public static int public_questionid = 0;
 }

第二步通过

    password = FormsAuthentication.HashPasswordForStoringInConfigFile(password + dr["注册IP"], "SHA1");
    if (dr["密码"].ToString() != password)
    {
     dr.Close();
     MyConn.Close();
     MyConn.Dispose();
     this.byts_errormsg.Text = "密码错误!请仔细核对!";
    }
    else
    {
     x.UserInfo info = new x.UserInfo();
     info.UserName = username;
     info.DataID = dr["id"].ToString();
     info.RoomID = "false";
     info.LastSave = DateTime.Now;
     info.MsgLine = 0;
     info.LastSaid = DateTime.Now;
     info.Sex = dr["性别"].ToString();
     info.Ico = (int) dr["头像"];
     info.Grade = (int) dr["等级"];
  ......

     dr.Close();
     string myonline = username + "|" + info.DataID + "|" + info.Sex + "|" + info.Ico + "|" + info.Grade + "|" + info.FGrade + "|" + info.Gold + "|" + info.CloseDoor + "|" + info.MyClass + "|" + info.MyHead + "|" + info.MyJob;
   
 

 this.Application.Lock();
     if (var.public_onlineinfo.ContainsKey(username) == true)
     {
      MyConn.Close();
      MyConn.Dispose();
      this.byts_errormsg.Text = "该用户名正在使用,不能重复登陆!";
      return;
     }
     var.public_onlineinfo.Add(username, myonline);
     var.public_online ++;
     this.Application.UnLock();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值