tags:

views:

125

answers:

4

I am using .net Windows Forms i need to maintain some date to check the condition. so i have to maintain it up to user logged out?

like session in ASP.NET

how can i do this? (note it should not expires until the user logged out)

+2  A: 

Just use a static variable in some class?

Vilx-
please elaborate. and i am not having single value. it set of values..
Ayyappan.Anbalagan
@Ayyappan.Anbalagan - then make the static variable a list of values, or have a few of them
Mark Heath
oh thank u........
Ayyappan.Anbalagan
A: 

You can use session also in winforms apps, but I don't think this is the correct way to do it. Can you more details ?

Manu
Probably a static var will be ok. If you want to access from multiple assemblies create a static public class with a static public property that is a Dictionary<string, object>
Manu
A: 
class Program
{
    internal static Dictionary<string, object> GlobalVariables = new Dictionary<string, object>();

    static void Main(string[] args)
    {
        ...
    }
}
abatishchev
@Ayyappan.Anbalagan: Glad it helped! Could you please also 'plus' my answer?
abatishchev
A: 

I create Namespace like this

namespace nsGlobalData {

class GlobalData

{

    public static int GlobalOrgId;

 }

}

To Set:

GlobalData.GlobalOrgId = Convert.ToInt16(ds.Tables[1].Rows[0].ItemArray[0]);

ToGet

txtnamt.text=GlobalData.GlobalOrgId;

Ayyappan.Anbalagan
Exactly. In winforms you don't worry about `state` so much as `scope`. As long as a variable is still in scope you will be able to access its contents. Given that the compiler will not let you try to access a variable that is out of scope you should find it very simple compared to web development.
Phil