Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How ro create a global variable in Csharp

0 views
Skip to first unread message

Deecrypt

unread,
Jul 22, 2006, 11:52:07 AM7/22/06
to
Hi,
I would like to pickup a value from a textbox and make it available to
be used by every method within a class. I havent done anything like
this since VB 6. Any suggestions?


Cheers

Khurram

Nicholas Paldino [.NET/C# MVP]

unread,
Jul 22, 2006, 12:00:00 PM7/22/06
to
Khurram,

You will want to declare the field/property as static. This will make
the property/field accessible to anyone who references the assembly in the
app domain that can see the class (it might be internal, for example, and
not public).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Deecrypt" <kna...@gmail.com> wrote in message
news:1153583527.0...@s13g2000cwa.googlegroups.com...

Bruce Wood

unread,
Jul 22, 2006, 3:13:47 PM7/22/06
to

It sounds to me as though you don't need global variables. You don't
need the value to be accessible to every method in every class in your
entire application, do you?

Could you give more information about what you're doing: what is in the
text box, and what is the class doing? That would help us propose a
good solution.

Deecrypt

unread,
Jul 22, 2006, 5:53:41 PM7/22/06
to
Thank you for your replies,

I am loading an ASP.NET website application through a Windows Form.
The form passess a value to the website which the website uses as
parameters to consume certain webservices. I just wanted to have some
clean code and thought that there should be a better way than calling
valueTextBox.Text all the time.

Thank you again

Khurram

Khurram

unread,
Jul 22, 2006, 7:45:44 PM7/22/06
to
Just realised that I didnt fully answer the question. I only have one
class in the website and multiple methods. Would like to have this
value to be available to all methods, as it is the primary piece of
information required for all database queries being used.

Cheers

Khurram

Jon Skeet [C# MVP]

unread,
Jul 22, 2006, 11:18:56 PM7/22/06
to
Khurram <kna...@gmail.com> wrote:
> Just realised that I didnt fully answer the question. I only have one
> class in the website and multiple methods. Would like to have this
> value to be available to all methods, as it is the primary piece of
> information required for all database queries being used.

If it's within the same instance of the same class that you need to
access the value, just create an instance variable within that class.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

0 new messages