C# Language Reference
#error (C# Reference)
#error lets you generate an error from a specific location in your code. For example:
#error Deprecated code in this method.
Remarks
A common use of #error is in a conditional directive.
It is also possible to generate a user-defined warning with #warning (C# Reference).
Example
// preprocessor_error.cs
// CS1029 expected
#define DEBUG
class MainClass
{
static void Main()
{
#if DEBUG
#error DEBUG is defined
#endif
}
}
See Also
Reference
C# Preprocessor DirectivesConcepts
C# Programming GuideOther Resources
C# Reference
Community Content
EddyHo88
Same error from my C# - Unsafe code may only appear if compiling with /unsafe - eddyho-88@hotmail.c
class Test
{
public int num;
public Test(int i) { num = i; }
}
class FixedCode
{
class Program
{
unsafe static void Main(string[] args)
{
Test o = new Test(19);
fixed (int* p = &o.num)
{
Console.WriteLine("Initial value of o.num is " + *p);
*p = 10;
Console.WriteLine("New value of o.num is " + *p);
}
}
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\608-FixedCode\608-FixedCode\Program.cs 13 28 608-FixedCode
class UnsafeCode
{
unsafe static void Main()
{
int count = 99;
int* p;
p = &count;
Console.WriteLine("Initial value of count is " + *p);
*p = 10;
Console.WriteLine("New value of count is " + *p);
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\608-UnsafeCode\608-UnsafeCode-Errors\Program.cs 5 26 608-UnsafeCode
class PtrArithDemo
{
unsafe static void Main()
//static void Main(string[] args)
{
int x;
int i;
double d;
int* ip = &i;
double* fp = &d;
Console.WriteLine("int double\n");
for (x = 0; x < 10; x++)
{
Console.WriteLine((uint)(ip) + " " + (uint)(fp));
ip++;
fp++;
}
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\610-PtrArithDemo\610-PtrArithDemo\Program.cs 5 24 610-PtrArithDemo
{
public int num;
public Test(int i) { num = i; }
}
class FixedCode
{
class Program
{
unsafe static void Main(string[] args)
{
Test o = new Test(19);
fixed (int* p = &o.num)
{
Console.WriteLine("Initial value of o.num is " + *p);
*p = 10;
Console.WriteLine("New value of o.num is " + *p);
}
}
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\608-FixedCode\608-FixedCode\Program.cs 13 28 608-FixedCode
class UnsafeCode
{
unsafe static void Main()
{
int count = 99;
int* p;
p = &count;
Console.WriteLine("Initial value of count is " + *p);
*p = 10;
Console.WriteLine("New value of count is " + *p);
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\608-UnsafeCode\608-UnsafeCode-Errors\Program.cs 5 26 608-UnsafeCode
class PtrArithDemo
{
unsafe static void Main()
//static void Main(string[] args)
{
int x;
int i;
double d;
int* ip = &i;
double* fp = &d;
Console.WriteLine("int double\n");
for (x = 0; x < 10; x++)
{
Console.WriteLine((uint)(ip) + " " + (uint)(fp));
ip++;
fp++;
}
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\610-PtrArithDemo\610-PtrArithDemo\Program.cs 5 24 610-PtrArithDemo