Eddy Ho
Eddy Ho

Reputation: 31

Help, cannot how to run unsafe

How to run csc /unsafe *.cs

using System;

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-Errors\608-UnsafeCode-Errors\Program.cs 5 26 608-UnsafeCode

Upvotes: 2

Views: 355

Answers (1)

Oded
Oded

Reputation: 499312

It's a command line argument.

You use the Visual Studio command prompt and simply type it out.

You can also set this in the IDE, by going to the properties of the project, and in the Build tab select Allow unsafe code checkbox. See here.

Upvotes: 2

Related Questions