Static Value in Method

  • Thread starter Thread starter jp2msft
  • Start date Start date
J

jp2msft

In C/C++, I can include a static value inside a routine:

void Test()
{
static bool tested = false;
if (tested == false)
{
FullTest();
tested = true;
}
}

How do I declare a static value in C#?

Thanks,
Joe
 
In C/C++, I can include a static value inside a routine:

void Test()
{
  static bool tested = false;
  if (tested == false)
  {
    FullTest();
    tested = true;
  }

}

How do I declare a static value in C#?

Thanks,
Joe

"C# does not support static local variables (variables that are
declared in method scope). " - VS Documentation
 
In C/C++, I can include a static value inside a routine:

void Test()
{
  static bool tested = false;
  if (tested == false)
  {
    FullTest();
    tested = true;
  }

}

How do I declare a static value in C#?

Thanks,
Joe

C# does not support it. You can declare a static at a class level but
not in the method level
 
jp2msft said:
In C/C++, I can include a static value inside a routine:

void Test()
{
static bool tested = false;
if (tested == false)
{
FullTest();
tested = true;
}
}

How do I declare a static value in C#?

Move it outside (and add private).

It increases scope a bit, but it is what you do in C#.

Arne
 
Back
Top