predifined array of structures in C#?
-
Hello gurus, I'd like to know how is it possible to declare a predefined array of structure in C#? The C declaration is like this:
typedef struct st_move_def { int byte; int bit; } MOVE_DEF ; static MOVE_DEF move_tab [8][8] = { { {5, 8}, {3, 4}, {7, 6}, {4, 7}, {6, 3}, {2, 8}, {1, 5}, {8, 3} }, /*1*/ { {8, 4}, {4, 5}, {2, 4}, {7, 8}, {1, 3}, {6, 5}, {5, 1}, {3, 2} }, /*2*/ { {4, 1}, {2, 2}, {3, 3}, {1, 7}, {5, 2}, {7, 7}, {8, 6}, {6, 6} }, /*3*/ { {7, 5}, {5, 6}, {1, 4}, {8, 2}, {2, 7}, {6, 1}, {4, 8}, {3, 1} }, /*4*/ { {8, 8}, {1, 6}, {2, 1}, {6, 7}, {4, 2}, {7, 1}, {3, 5}, {5, 4} }, /*5*/ { {3, 7}, {5, 7}, {6, 2}, {1, 2}, {7, 3}, {2, 6}, {4, 6}, {8, 1} }, /*6*/ { {6, 4}, {8, 5}, {7, 2}, {5, 3}, {1, 1}, {3, 8}, {2, 5}, {4, 4} }, /*7*/ { {3, 6}, {4, 3}, {6, 8}, {2, 3}, {8, 7}, {1, 8}, {5, 5}, {7, 4} } /*8*/ };
and I need to translate it into C#. How can I do this please? Best regards. Fred.There is no spoon.
-
Hello gurus, I'd like to know how is it possible to declare a predefined array of structure in C#? The C declaration is like this:
typedef struct st_move_def { int byte; int bit; } MOVE_DEF ; static MOVE_DEF move_tab [8][8] = { { {5, 8}, {3, 4}, {7, 6}, {4, 7}, {6, 3}, {2, 8}, {1, 5}, {8, 3} }, /*1*/ { {8, 4}, {4, 5}, {2, 4}, {7, 8}, {1, 3}, {6, 5}, {5, 1}, {3, 2} }, /*2*/ { {4, 1}, {2, 2}, {3, 3}, {1, 7}, {5, 2}, {7, 7}, {8, 6}, {6, 6} }, /*3*/ { {7, 5}, {5, 6}, {1, 4}, {8, 2}, {2, 7}, {6, 1}, {4, 8}, {3, 1} }, /*4*/ { {8, 8}, {1, 6}, {2, 1}, {6, 7}, {4, 2}, {7, 1}, {3, 5}, {5, 4} }, /*5*/ { {3, 7}, {5, 7}, {6, 2}, {1, 2}, {7, 3}, {2, 6}, {4, 6}, {8, 1} }, /*6*/ { {6, 4}, {8, 5}, {7, 2}, {5, 3}, {1, 1}, {3, 8}, {2, 5}, {4, 4} }, /*7*/ { {3, 6}, {4, 3}, {6, 8}, {2, 3}, {8, 7}, {1, 8}, {5, 5}, {7, 4} } /*8*/ };
and I need to translate it into C#. How can I do this please? Best regards. Fred.There is no spoon.
I think you need to do this: { new MOVE_DEF(5,8), new MOVE_DEF (7,6, etc
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I think you need to do this: { new MOVE_DEF(5,8), new MOVE_DEF (7,6, etc
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, Thanks for your answer. Is there a "static" way to initialize the members like in C/C++? Best regards.
There is no spoon.
Not that I know of
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Not that I know of
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, Thanks for your answer. Is there a "static" way to initialize the members like in C/C++? Best regards.
There is no spoon.
Hi, you can have a "static constructor" containing code to initialize static members (including const). AFAIK you must be careful when a static constructor calls onto another class that also has a static constructor, I think there is some unwanted behavior then. But it works well in simple cases. :)
Luc Pattyn [My Articles]