473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Variable help (very simple question)

Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se

Nov 15 '05 #1
5 916
Davor wrote:
Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se

class test
{
private int firstInt;
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
}

Nov 15 '05 #2
you need to write:

static int firstInt;
"Davor" <da****@comhem.se> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se

Nov 15 '05 #3
Scott C. Reynolds wrote:
Davor wrote:
Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se

class test
{
private int firstInt;
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
}

i'm sorry...I was in such a hurry i skipped the most important
part...you definitely need a "static" in that variable declaration.

Nov 15 '05 #4
Scott C. Reynolds wrote:
Davor wrote:
Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se

class test
{
private int firstInt;
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
}

Tried this before, but what I get is an error saying
"An object reference is required for the nonstatic
field, method, or property"

--
Davor Babic´
----------------
da****@comhem.se

Nov 15 '05 #5
DeepDiver wrote:
you need to write:

static int firstInt;
"Davor" <da****@comhem.se> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
Ok, this is what I want to do:

class test
{
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
int firstInt;
]

So, basically, how should I write that
so that both of them can use 'firstInt'?
=================
Davor Babic´
da****@comhem.se


Thanks! This worked. I was thinking about
trying this myself, but I was not shure if
it would work.
--
Davor Babic´
----------------
da****@comhem.se

Nov 15 '05 #6

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
7
by: NS Develop | last post by:
What's wrong with the following: void SomeClass::someMethod(void) { A *ptrA = NULL; ptrA = &A(); .... }
7
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
5
by: Marc Rivait | last post by:
Here is a very interesting scenario. I have a simple test application that loads a page and sets a session variable on the load event. On the first page there is a link to a second page. The...
1
by: Hose B | last post by:
HI all, I have a legacy app in which users can pick various page templates. There is a template preview dialog. It works such that they view a list of icons in an asp page that represent each...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
4
by: Phillip Vong | last post by:
I'm a newbie using VS2005 to learn and test. I'm testing against the Northwind DB. I created a simple variable called "myVariable" and I assigned it the character "c". I want my SQL query to use...
15
by: tatsudoshi | last post by:
Hello, I have this class http://pastebin.com/807571, where I set some variables on __construct. Originaly I set the $total_? variables when the function showLayout() was called. I know pastebin...
5
by: Daz | last post by:
Hi everyone. Another simple question which should hopefully warrent a simple answer. I would like a function to be run whenever a variable is updated. I have tried binding the onchange event...
2
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, When I try to compile the below code snippet, I get the compile error listed below in this question. In the lines below the loop, the variable j does not excist, however, trying to create it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.