Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Visual Studio 2010\Projects\Unsafe\Unsafe\Program.cs 6 24 Unsafe
Error 2 Unsafe code may only appear if compiling with /unsafe C:\Visual Studio 2010\Projects\Unsafe\Unsafe\Program.cs 10 31 Unsafe
using System;

class Unsafe
{
    unsafe static void SquarePtrParam(int *p)
    {
        *p *= *p;
    }

    unsafe public static void Main(string[] args)
    {
        int i = 5;
        SquarePtrParam(&i);
        Console.WriteLine(i);
    }
}


[EMAIL REMOVED] Thanks.
Posted
Updated 9-Dec-10 1:44am
v3

You need to add "/unsafe" switch in the compiling options in visual studio.
 
Share this answer
 
Comments
Dalek Dave 9-Dec-10 3:56am    
Good Call.
Select the project properties. In 'Build' tab check the checkbox
'Allow unsafe code'.Build the application and run the file.
Regards,
Vineeth
 
Share this answer
 
'Allow unsafe code" still error Program "C:\*" does not contain a static "Main" method suitable for an entry point - Help me, THANKS
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900