Skip to content

How to make a Private Variable Public??

Mukesh Karanwal

Asked Apr 8, 2010, 8:47 PM EDT4 answers
Share
LinkedInX
Hey All,
How can I take my private variable in the method and make it Public for another method to get a hold of it?
I have a class, Class1.cs. i have a method there which has a variable, now i want to use the value of this variable on a seperate form'Button_Click event!
 How to go about this??
Thanks,

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Hirendra Sisodiya
    0
    why are you not making this as public, i think you should be declare this variable as public....
    thanks
    0
  • 0
    find attched the code.
    My application is such that i need to fetch a variables values which is defined and has some value inside a function.
    and i need this value on some other form.
    thanks
    0
  • Hirendra Sisodiya
    0
    Hello Mukesh
    apply this code on form1:
    private void button1_Click(object sender, EventArgs e)
    {
    Class1 myCLS = new Class1();
    //You need to call function my()
    myCLS.my();
    MessageBox.Show(myCLS.mySTR.ToString());
    }
     
    thanks
    Please mark as answere if it helps
    0
  • 0
    Yeah, its done..
    Thanks a lot..:-)
    0