首页 新闻 赞助 找找看

C++结构体内含链路(指向结构体本身的指针)如何转换为C#

0
悬赏园豆:10 [待解决问题]

struct Student{   
 char *name;   
 int score;   
 struct Student* next;   
};  

如何转成C#的代码。

 

stu.name: 0019FEE0 stu.score: 0019FEEC
stu.next->name: 00506C40 stu.next->score: 00506C4C

这个是测试内存地址的结果。

月光小提琴的主页 月光小提琴 | 初学一级 | 园豆:44
提问于:2012-11-24 22:11
< >
分享
所有回答(1)
0

就没看明白你的问题是说的什么,如果是pinvoke场景中要和c语言的dll交换这样的一个结构的数据的话,定义方式应该是如下所示:

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Student {
    
    /// char*
    [MarshalAsAttribute(UnmanagedType.LPStr)]
    public string name;
    
    /// int
    public int score;
    
    /// Student*
    public System.IntPtr next;
}
天方 | 园豆:5407 (大侠五级) | 2012-11-25 17:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册