Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. predifined array of structures in C#?

predifined array of structures in C#?

Scheduled Pinned Locked Moved C#
questioncsharpdata-structures
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bouli
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • B bouli

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      B 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        B Offline
        B Offline
        bouli
        wrote on last edited by
        #3

        Hi, Thanks for your answer. Is there a "static" way to initialize the members like in C/C++? Best regards.

        There is no spoon.

        C L 2 Replies Last reply
        0
        • B bouli

          Hi, Thanks for your answer. Is there a "static" way to initialize the members like in C/C++? Best regards.

          There is no spoon.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          B 1 Reply Last reply
          0
          • C Christian Graus

            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 )

            B Offline
            B Offline
            bouli
            wrote on last edited by
            #5

            ok, thanks. I have done a class and made some "new" on it. it seems to work :) Best regards.

            There is no spoon.

            1 Reply Last reply
            0
            • B bouli

              Hi, Thanks for your answer. Is there a "static" way to initialize the members like in C/C++? Best regards.

              There is no spoon.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups