3

I have 2 structs in C language:

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

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

and C++ code:

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

I'm trying to convert they to 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; }
    }
}

But I don't know how to convert line:

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

to C#?

How can I convert this line to C#?

millimoose
  • 39,073
  • 9
  • 82
  • 134
hoangkianh
  • 631
  • 4
  • 13
  • 1
    Careful with the `char` in C to `char` in C# conversion. They can have a different meaning. `char` in C# really means a unicode character. And what exactly is `m_Down`? – Dirk May 25 '13 at 15:23
  • I'm missing, m_Down is CSide. – hoangkianh May 25 '13 at 15:40
  • 1
    `m_Down->m_Blocks[0][1] == *m_Down` looks strange for me, except there's an overloaded operator. – Ken Kin May 25 '13 at 17:01
  • 1
    What is the logic behind this code? – akalenuk May 25 '13 at 17:10
  • Is the code for something like [this question](http://stackoverflow.com/questions/15368699/deep-copying-an-array-c-sharp-without-serialization)? – Ken Kin May 25 '13 at 17:29
  • 1
    You have a type error there, I think. `m_Down->m_Blocks[0][1]` is of type `char`, while `*m_Down` is of type `CSide` – Zach Johnson May 25 '13 at 18:25
  • @ZachJohnson: It *might* be error, but if there's an overloaded operator of `==`, then it's no problem. – Ken Kin May 25 '13 at 18:35
  • 2
    @KenKin yeah, just guessing the overload might be to compare the m_side field...? We need more info. – Zach Johnson May 25 '13 at 19:00
  • @Dirk a `char` in C# is a UTF-16 code unit, not a Unicode character `` (but yes, in either case, it is quite different from C++'s `char` which is defined to be a byte. – jalf May 25 '13 at 21:30

1 Answers1

1

this line make no sense, i guess it's always evaluate to false.

What you can do is to set a breakpoint on that line and perform a quick watch, evaluate *m_Down to make sure there's no overload operator.

Then, evaluate the condition. Depending on your type of project, put some printf("inside the if")/printf("inside the else"), messagebox or write it in a file. If the condition is evaluate to true, print the value of m_Down->m_BLocks[0][1] and *m_Down...

Make sure you first understand the logic behind this line. Once you understand it, it will be easy to write it in c#

PS: in C#, use Byte instead of Char

MLeblanc
  • 1,816
  • 12
  • 21