DOTNET的 - 什么是INT *? [英] DotNet - What is int*?

查看:224
本文介绍了DOTNET的 - 什么是INT *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题,我导入一个DLL函数,参数都为int *。 当我尝试输入方法(0),我得到一个错误,说:int和INT *不能将

simple question, I import a DLL function and the parameter are int*. When I try to enter Method(0), I get an error which says: "int and int* can not convert".

那是什么意思?

推荐答案

这是一个指向int经典的C表示法。每当类型后跟一个 * ,它指的类型作为的指针那个类型。在C#中,不像在C,你必须明确定义功能不安全使用指针,除了启用的不安全 code。在项目属性。指针类型也不能直接互换的具体类型,这样类型的引用必须首先考虑。为了得到一个指向另一种类型,如int,在C#(或C和C ++的这个问题),您必须使用引用操作&安培; (符号)在变量前面你希望得到一个指向:

That is classic C notation for a pointer to an int. Whenever a type is followed by a *, it denotes that type as a pointer to that type. In C#, unlike in C, you must explicitly define functions as unsafe to use pointers, in addition to enabling unsafe code in your project properties. A pointer type is also not directly interchangeable with a concrete type, so the reference of a type must be taken first. To get a pointer to another type, such as an int, in C# (or C & C++ for that matter), you must use the dereference operator & (ampersand) in front of the variable you wish to get a pointer to:

unsafe
{
    int i = 5;
    int* p = &i;
    // Invoke with pointer to i
    Method(p);
}

不安全code C#

下面是不安全code的一些关键文章,并在C#中使用指针。

Below are some key articles on unsafe code and the use of pointers in C#.

  • Unsafe contexts
  • Pointer Types
  • Fixed and movable variables
  • Pointer conversions
  • Pointers in expressions
  • The 'fixed' statement
  • Stack allocation
  • Dynamic memory allocation

这篇关于DOTNET的 - 什么是INT *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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