using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Class1.urlcount = 5;
Console.WriteLine(Class1.urlcount);
Console.ReadLine();
}
}
public static class Class1
{
static private int uc;
public static int urlcount
{
get
{
return uc;
}
set
{
uc = value;
}
}
}
}
I found no problem, try the above code
On Fri, May 14, 2010 at 4:42 PM, neuromancer <[email protected]> wrote:
> I am new to C#. I wanted to create a "global" variable, and I found
> advice on the net that said create a static class and make a variable
> in it, and that will be your global variable.
> So I made:
> public static class Class1
> {
> static private int uc;
>
> public static int urlcount
> {
> get
> {
> return uc;
> }
> set
> {
> uc = value;
> }
> }
>
> }
> Then in my main program, I tried to so something like:
> Class1.urlcount = 5;
> This should work. I should not need to create an instance of Class1,
> because it is a static class. But it does not work. Instead I get
> the error message:
> "object reference not set to an instance of an object".
> What am I missing?
> Thanks,
> NM
>