You receive the "CS1513" and "CS1022" error messages when you use the volatile modifier on local variables in Visual C# .NET or in Visual C# 2005 (814907)
The information in this article applies to:
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual C# .NET (2003)
SYMPTOMSWhen you use the volatile modifier on local variables in Visual C# .NET or Visual C# 2005 code, you receive
the following compiler error messages: error CS1513:
} expected error CS1022: Type or namespace definition, or end-of-file
expected Note In Visual C# 2005, you receive
the following compiler error message: error CS0246: The type or namespace name 'STAThread' could
not be found (are you missing a using directive or an assembly
reference? CAUSEYou cannot use the volatile modifier on local variables or on function variables. Use the volatile modifier only with class variables. STATUS This
behavior is by design.WORKAROUND To work around this behavior, declare the volatile variables at class scope as follows:
class test
{
volatile int x = 0;
[System.STAThread]
static void Main()
{
}
}
Modification Type: | Major | Last Reviewed: | 1/19/2006 |
---|
Keywords: | kbCompiler kbprb KB814907 kbAudDeveloper kbAudITPRO |
---|
|