Global Variable

G

Guest

I know in vb.net you can declare a global variable, but how do you declare one in c#. I want to make a connection class with the path and have it accessed by anther class or method.


Thank you
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi freddy,

Declare that variable as a static member of a class. This way you can access
it from anyware.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


freddy said:
I know in vb.net you can declare a global variable, but how do you declare
one in c#. I want to make a connection class with the path and have it
accessed by anther class or method.
 
S

Shakir Hussain

You have to declare public variable inside the class like

public string myVariable = "Test";

You have to store MyOtherClass as member in the class where you want to
access to like

public MyOtherClass mOtherClass;

To access the public variable in of MyOtherClass you can say

mOtherClass.MyVariable

Other way is to declare variable as static member. VB approach wont be
applicable in c# in this case.

--
Shak
(Houston)


freddy said:
I know in vb.net you can declare a global variable, but how do you declare
one in c#. I want to make a connection class with the path and have it
accessed by anther class or method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top