Variable help (very simple question)

  • Thread starter Thread starter Davor
  • Start date Start date
D

Davor

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´
(e-mail address removed)
 
Davor said:
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´
(e-mail address removed)
class test
{
private int firstInt;
public static void crap1()
{
// This won't work
firstInt = 6;
}
public static void crap2()
{
// Nor will this
firstInt = 2;
}
}
 
Scott said:
Davor said:
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´
(e-mail address removed)
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"
 
Scott said:
Davor said:
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´
(e-mail address removed)
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.
 
DeepDiver said:
you need to write:

static int firstInt;


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´
(e-mail address removed)
Thanks! This worked. I was thinking about
trying this myself, but I was not shure if
it would work.
 
Back
Top