Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Variables in C#

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hello,

I am a newbie to C# and i wich to be able to create a variable that can be used by several functions. For example, when the page is loaded I want to create a string that can be then used by different functions on the same page. Also, if possible I would like to make a function that makes a connection to a database and then other functions could use the connection. COuld this be done??

Neil
 
Hi NeilV

I don't know if this is what you are looking for - but take a look at Session Variables and see if that is what you want.

Hope you come right

Craftor

:cool:
 
Just make your variable declarations right under the class declaration, outside the scope of any function.

Right along side any other page level objects, such as textboxes, datagrids, and the like:

Private String myString;

And this myString var will be available to any and all methods/properties of that class. Same would be true for a connection.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top