c# - 将 C++ 指针结构转换为 C#

标签 c# c pointers

我有 2 个 C 语言结构:

struct CSquare
{
    char Side;
    int  Row;
    int  Col;    
};

struct CSide
{
   char     m_Side;           
   char     m_Blocks[3][3];     
   CSquare  *m_Moves;
};

和C++代码:

int Count = 0;
int Flag = 0;
if (m_Down->m_Blocks[0][1] == *m_Down)
{
    Count++;
    Flag |= 2;
    // type of m_Down is CSide
}

我正在尝试将它们转换为 C#:

public class Square
{
    public char Side { get; set; }
    public int Row { get; set; }   
    public int Col { get; set; }
}

public class CubeSide
{
    private char Side { get; set; }
    private char[,] _block = new char[3, 3];
    private Square[] moves;

    public char[,] Block
    {
        get { return _block; }
        set { _block = value; }
    }

    internal Square[] Moves
    {
        get { return moves; }
        set { moves = value; }
    }
}

但我不知道如何转换行:

if (m_Down->m_Blocks[0][1] == *m_Down)

到 C#?

如何将此行转换为 C#?

最佳答案

这一行没有意义,我猜它总是求值为 false。

您可以做的是在该行上设置一个断点并执行快速观察,评估 *m_Down 以确保没有重载运算符。

然后,评估条件。根据您的项目类型,放一些 printf("inside the if")/printf("inside the else")、messagebox 或将其写入文件。如果条件评估为真,则打印 m_Down->m_BLocks[0][1] 和 *m_Down 的值...

请确保您首先了解此行背后的逻辑。一旦理解了,用c#写起来就很容易了

PS: 在 C# 中,使用 Byte 而不是 Char

关于c# - 将 C++ 指针结构转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16750844/

相关文章:

c# - 是否有 Visual Studio Load Test 开源等效项 - 或者类似的东西?

c# - 如何在 XmlNode 中获取文本

c - 如何通过从 ini 文件中提取值来更新指针的值?

c - 使用 static 而不是 malloc - C 语言

c - 在函数中将数组声明为静态的目的是什么?

C# 使用 System.Type 作为通用参数

c# - 将 Expression<Func<t, bool>> 转换为 Expression<Func<x, bool>>

c - (C, pthreads) 让多个线程同步并一起继续

c错误: assignment makes integer from pointer without a cast [-Werror=int-conversion]

c++ - 一个对象可以接近最大指针值多远才能避免溢出?