使用不安全的代码

编程入门 行业动态 更新时间:2024-10-26 02:34:55
本文介绍了使用不安全的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

即时通讯在我的函数中使用不安全的代码...

i m using unsafe code in my function like this...

public unsafe void swap(int* p_x, int* p_y) { int temp = *p_x; *p_x = *p_y; *p_y = temp; }

但是当我编译我的应用程序时我收到错误 只有在使用/ unsafe进行编译时才会出现不安全的代码 请帮助我

but when I compile my application i get error "Unsafe code may only appear if compiling with /unsafe" please help me

推荐答案

为什么不避免不安全的代码?你可以通过引用传递值类型,你只需要明确。 Why not just avoid the unsafe code? you can after all pass the value type by reference, you just have to be explicit. public void swap(ref int x, ref int y) { int temp = x; x = y; y = temp; }

来自JSOP:这实际上是更正确的答案。除非使用不安全的代码有明显的优势,否则应尽可能避免使用它。这个答案从我那里得到了5分。

From JSOP: This is actually the more correct answer. Unless there's a clear advantage to using unsafe code, you should avoid it whenever possible. This answer gets a 5 from me.

我同意解决方案2. 尽可能避免使用不安全的代码。 当你还想使用不安全的代码时: 错误你得到的意思是: 编译/不安全。 在Visual Studio中 项目属性=> Build =>检查允许不安全代码CheckBox。 祝你好运, Stephan Hi, I agree with Solution 2. Avoid unsafe code whenever possible. When you still want to use unsafe code: The error you get means: "Compile with /unsafe". In your Visual Studio under Project Properties => Build => Check the "Allow unsafe code" CheckBox. Best regards, Stephan

更多推荐

使用不安全的代码

本文发布于:2023-11-15 06:30:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不安全   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!