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 NRank #4,788 · 325 reputationPosted Dec 26, 2010, 11:55 PM EST
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 NRank #4,788 · 325 reputationPosted Dec 26, 2010, 10:38 PM EST
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
ArshadRank #2,492 · 564 reputationPosted Dec 26, 2010, 10:49 PM EST
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
Pravin GhadgeRank #1,340 · 1.3K reputationPosted Dec 26, 2010, 11:49 PM EST
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
Pravin GhadgeRank #1,340 · 1.3K reputationPosted Dec 27, 2010, 1:52 AM EST
Problem is solved!
Great Soln........
Santhosh NRank #4,788 · 325 reputationPosted Dec 27, 2010, 1:58 AM EST