[英]How to declare c++ pointer in C#
BIRDREADING *bird_data;
bird_data = &frame.reading[i];
How to declare such in C#?如何在 C# 中声明这样的?
update1:更新1:
i want To call a C++ DLL/lib or to rewrite in C#.我想调用 C++ DLL/lib 或在 C# 中重写。 Actually i try to solve my own question on this link.
实际上,我尝试在此链接上解决我自己的问题。 Use a variable directly(data return are same in an array) or with pointer?
直接使用变量(数组中的数据返回相同)还是使用指针? Try my luck to solve the question after i convert above into c#
在我将上面转换为 c# 后,试试运气来解决问题
In c# you can declare pointers which called as unsafe programming.在 c# 中,您可以声明称为不安全编程的指针。
Example:例子:
unsafe {
int iData = 10;
int* pData = &iData;
Console.WriteLine("Data is " + iData);
Console.WriteLine("Address is " + (int)pData );
}
Check this article: Writing Unsafe code using C#查看这篇文章:使用 C# 编写不安全代码
type* identifier;
It depends, will BIRDREADING be a reference type?这取决于,BIRDREADING 会是引用类型吗?
You can't declare pointers to reference types from Pointer Types (C#)您不能从指针类型 (C#)声明指向引用类型的指针
Any of the following types may be a pointer type:
以下任何类型都可以是指针类型:
sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.sbyte、byte、short、ushort、int、uint、long、ulong、char、float、double、decimal 或 bool。
Any enum type.任何枚举类型。
Any pointer type.任何指针类型。
Any user-defined struct type that contains fields of unmanaged types only.任何仅包含非托管类型字段的用户定义结构类型。
So for your example, giving that BIRDREADING statisifies the above因此,对于您的示例,给出 BIRDREADING 统计了上述内容
BIRDREADING *bird_data;
Also, what do you want to use the pointer for?另外,你想用指针做什么? Are you sure you need a pointer?
你确定你需要一个指针吗?
If BIRDREADING
is a class it is a pointer by definition and you don't need to do anything special:如果
BIRDREADING
是 class 根据定义它是一个指针,你不需要做任何特别的事情:
BIRDREADING bird_data;
bird_data = frame.reading[i];
If it's a struct then getting its poiner depends on the context.如果它是一个结构,那么获取它的指针取决于上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.