不安全代码有什么错误? [英] What is the error about unsafe code?

查看:98
本文介绍了不安全代码有什么错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误1只有在使用/unsafe C:\ Visual Studio 2010 \ Projects \ Unsafe \ Unsafe \ Program.cs进行编译时,才会出现不安全代码6 24不安全
错误2只有在使用/unsafe C:\ Visual Studio 2010 \ Projects \ Unsafe \ Unsafe \ Program.cs进行编译时,才会出现不安全代码10 31不安全

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.

推荐答案

您需要在Visual Studio的编译选项中添加"/unsafe"开关.
You need to add "/unsafe" switch in the compiling options in visual studio.


选择项目属性.在构建"标签中,选中复选框
允许不安全的代码".生成应用程序并运行文件.
问候,
Vineeth
Select the project properties. In ''Build'' tab check the checkbox
''Allow unsafe code''.Build the application and run the file.
Regards,
Vineeth


仍然允许不安全代码"仍然错误程序"C:\ *"不包含适用于入口点的静态"Main"方法-谢谢
''Allow unsafe code" still error Program "C:\*" does not contain a static "Main" method suitable for an entry point - Help me, THANKS


这篇关于不安全代码有什么错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆