永发信息网

在C#中如何创建一个缓存呢?高手求解哈!

答案:4  悬赏:0  手机版
解决时间 2021-03-02 14:58
  • 提问者网友:焚苦与心
  • 2021-03-01 21:59
问题是这样的,我有一个登录窗体和2个主程序窗体,在第一个窗体中我要创建一个缓存储存我输入的用户名和密码,然后在2个主程序窗体中调用这个缓存中的用户名和密码。
最佳答案
  • 五星知识达人网友:山有枢
  • 2021-03-01 22:13
如果 你是 写的 WinForm 程序的话,可以写一个类来专门保存各种信息,然后将登录名和密码加入到该类的全局静态变量中。
如果是webform 的话可以写入 session ,cookise 等。
全部回答
  • 1楼网友:孤独的牧羊人
  • 2021-03-02 01:14
恩恩,静态变量 public class FormCache { private static System.Collections.Hashtable ht = new System.Collections.Hashtable(); public static System.Windows.Forms.Form GetForm(string formtype) { if (ht.Contains(formtype)) { } else { ht.Add(formtype, System.Activator.CreateInstance(System.Type.GetType(formtype))); } Form temp= ht[formtype] as Form; temp.FormClosing += new FormClosingEventHandler(temp_FormClosing); return temp; } public static System.Windows.Forms.Form GetForm(string formtype,object[] obj) { if (ht.Contains(formtype)) { } else { Type type=System.Type.GetType(formtype); //object obj2=System.Activator.CreateInstance(type, obj, null); //object obj3 = System.Activator.CreateInstance(type, obj); ht.Add(formtype, System.Activator.CreateInstance(type,obj)); } Form temp = ht[formtype] as Form; temp.FormClosing += new FormClosingEventHandler(temp_FormClosing); return temp; }
  • 2楼网友:毛毛
  • 2021-03-01 23:39
你好! 在2个主程序窗体中调用这个缓存中的用户名和密码。这个技术不是缓存,是保存。 用 Session 或者Cookie即可实现。 登录窗体:session("户名和密码") = "输入的用户名和密码"; 2个主程序窗体中调用这个用户名和密码: a=session("户名和密码") ; 打字不易,采纳哦!
  • 3楼网友:杯酒困英雄
  • 2021-03-01 23:13
winform你要存用户名密码 存在一个全局变量里面 或者写成文件保存在本地存着
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯