日期:2014-05-20  浏览次数:21231 次

winform中有没有类似webform中的session的东西?
如题,我想用它保存一个值,比如说用户的权限。这个东西怎么使用。
或者说如果没有这种东西,有没有其他的方法来保存这个值,全局变量么?

------解决方案--------------------
可以写个单例模式的类来保存全局的东西。

Singleton

C# code
using System;
using System.Collections.Generic;
using System.Text;

namespace Pattern.Singleton
{
  /**//// <summary>
  /// 泛型实现单例模式
  /// </summary>
  /// <typeparam name="T">需要实现单例的类</typeparam>
  public class Singleton<T> where T : new()
  {
    /**//// <summary>
    /// 返回类的实例
    /// </summary>
    public static T Instance
    {
      get { return SingletonCreator.instance; }
    }

    class SingletonCreator
    {
      internal static readonly T instance = new T();
    }
  }
}

------解决方案--------------------
用XML也行啊
------解决方案--------------------
没有,全局变量
XML,ini等文件
C/S是一直保持状态的
http://topic.csdn.net/u/20071109/11/fd9aec31-04ef-4cd8-a965-116dec01ecac.html
------解决方案--------------------
http://topic.csdn.net/t/20060724/09/4899772.html
------解决方案--------------------
有全局,静态变量的.