Hi Roy,
First of all ...
It is never the case, that an array or a variable has to be seen by the
whole program. sometimes this
is the case for constants, but not for variables. You're working in an
object-oriented environment,
and you should change the design of your program accordingly.
If you're completely new to object-oriented programming, you should make
yourself familiar with it,
since it has nothing to do with structured programming.
But anyway ... here's a way how you can make your variable global:
Create a new class and declare the variable as a static field:
public class GlobalValues {
public static int GlobalVariable = 0;
}
Now you can access it from anywhere using:
GlobalValues.Gl obalVariable = ...;
And btw.: No, there is no way to just declare a variable without putting it
inside a Datatype.
REgards,
Frank Eller
"Roy Gourgi" <ro***@videotro n.ca> schrieb im Newsbeitrag
news:hB******** ************@we ber.videotron.n et...
Hi,
I am new to C#. I am trying to create some variables and arrays that can
be seen throughtout the whole program. I have no choice as they have to be
seen by the whole program. Where and how do I declare them? I tried
putting the variable gnSum and gaArray in my Main() method but the rest of
the program does not see them.
class RefValTest
{
public static int Main()
{
int gnSum=0; // global variable
int[] gaArray= new int [7]; // global array
return 0;
}
}
TIA
Roy