如果您使用指针(不安全code)在C#中? [英] Should you use pointers (unsafe code) in C#?

查看:167
本文介绍了如果您使用指针(不安全code)在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在C#code使用指针?有什么好处?难道是建议由男方(微软)?

Should you use pointers in your C# code? What are the benefits? Is it recommend by The Man (Microsoft)?

推荐答案

从人自己:

的指针的使用很少需要在C#,但也有一些情况,需要它们。作为例子,使用不安全的上下文,以允许指针是由下列情况下保证:

The use of pointers is rarely required in C#, but there are some situations that require them. As examples, using an unsafe context to allow pointers is warranted by the following cases:

  • 在现有的结构上盘交易
  • 涉及的指针结构在其中高级COM或平台调用场景
  • 在性能关键code

在其他情况下,使用不安全的情况下不鼓励。

The use of unsafe context in other situations is discouraged.

具体而言,不安全的情况下不应该被用来尝试写C code在C#。

注意:

code。使用不安全的上下文无法验证是安全的编写,因此它仅被执行时,code是完全可信的。换句话说,不安全code不能在不受信任的环境中执行。例如,你不能直接从互联网上运行不安全的code。

Code written using an unsafe context cannot be verified to be safe, so it will be executed only when the code is fully trusted. In other words, unsafe code cannot be executed in an untrusted environment. For example, you cannot run unsafe code directly from the Internet.

参考

这篇关于如果您使用指针(不安全code)在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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