none
Always error from Unsafe code. WHY.!!! eddyho-88@hotmail.com RRS feed

  • Question

  • 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

    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

    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

    Sample the error

    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);
                }
            }
        }
    }

    Tuesday, December 7, 2010 2:25 AM

All replies

  • It looks like you code did not pass compiler check, let along blow up in a debugger. Try the Visual C# language forum instead.

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Thursday, December 16, 2010 2:08 AM