I want 2 define public variable in Window application of C#.net.
In V.B..net there is module in which we can define public variable which will remain public in whole project.
Bt in C#.net it changes in every form.It gives me default value of class (where i have define variable).
I have searched lot on google bt i have nt get appropriate Answer.
Plz help me out....
Loading

Santhosh NPosted Dec 27, 2010, 4:55 AM
static class Class1
{
private static boolvar1 = false;
public static bool varProp
{
get { return var1; }
set { var1 = value; }
}
}
In your class1 declare this property and set to false initially as desired..once print button is clicked no matter in which calss set this to true
Class1.varProp = true;
and you can check this one whereever required (in closing event)
If you can not modify class1 to static define a seperate class and have this property over there
Santhosh NPosted Dec 27, 2010, 6:58 AM
Pravin GhadgePosted Dec 27, 2010, 6:52 AM
Problem is solved!
Great Soln........
Pravin GhadgePosted Dec 27, 2010, 4:49 AM
But it is nt helping in my project
Actually my problem is that:
I have to check condition at MDI_Formclosing() that if particular bool variable
for ex:bool Print=false is declared at my class class1 And it is getting true after click of print button At form1
And i have 2 check that MDI should not closed when this condition is satisfy
So i want 2 take 1 public variable for checking this
Plz reply me
ArshadPosted Dec 27, 2010, 3:49 AM
You do one thing, make a class and use the constant. it will be a kind of module i.e there in VB.NET.
public class const
{
public const string APPLICATION_NAME = "ARSHAD";
}
Regards,
Arshad
Santhosh NPosted Dec 27, 2010, 3:38 AM
static class Class1
{
private static string var1 = "";
public static string varProp
{
get { return var1; }
set { var1 = value; }
}
}
you could access and assign this public global variable using
Class1.varProp