473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How ro create a global variable in Csharp

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

Jul 22 '06 #1
5 12592
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]
- mv*@spam.guard. caspershouse.co m

"Deecrypt" <kn*****@gmail. comwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.com.. .
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

Jul 22 '06 #2

Deecrypt wrote:
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?
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.

Jul 22 '06 #3
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.Te xt all the time.

Thank you again

Khurram
Bruce Wood wrote:
Deecrypt wrote:
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?

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.
Jul 22 '06 #4
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

Deecrypt wrote:
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.Te xt all the time.

Thank you again

Khurram
Bruce Wood wrote:
Deecrypt wrote:
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?
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.
Jul 22 '06 #5
Khurram <kn*****@gmail. comwrote:
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.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
24188
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); function loadUrlVariables() { varString = location.search;
22
2763
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so that for example the following code would work as well in browsers as under Windows Scripting Host: str = "tableA";
8
3194
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { } Client.prototype.fullname = "John Smith"; var s = "Client"; eval("var o = new " + s + "();"); alert(o.fullname);
3
1993
by: Mohammed Abdel-Razzak | last post by:
Dear sirs How can I declare a variable(Global) that all forms in my project can see and use it thanks Mohammed
8
4070
by: Paw Pedersen | last post by:
Is there a way to save a variabel that can be access from a static method? I hope there would be some way to save it in memory so I don't have to save it in a file. It's only for a few minutes the information have to be stored. It's a simple static method that will be call with a guid in the input parameter and return a integer telling how many times it have been called with exactly this guid. After 1 minute it will not be called with the...
8
2891
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger class that I want its instance to be accessible from any other classe in the project. There is also a bunch of constants that I want to be public for the
19
2071
by: Shiv Kumar | last post by:
I see that the Application_OnStart event is fired only once for a certain application. I'm interested in creating a "global" object (an object that will be available to all requests for the application). I thought I could use this event to create an instance of my object. I find that the event does get fired and an instance is created. However, when I reference this object from a page it is null. What gives? What is the recommended way...
2
3061
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is what I'm hoping to achieve. I've never before had to use Javascript closures, but now I do, so I'm making an effort to understand them. I've been giving this essay a re-read: http://jibbering.com/faq/faq_notes/closures.html
4
12447
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.