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. struct array in C#

struct array in C#

Scheduled Pinned Locked Moved C#
questioncsharpc++comdata-structures
8 Posts 5 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.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, How can I perform the following C++ structure code within C#?struct EmpStruct { char name[15]; char surname[15]; }EMP[100];
    Many thanks in advance Regards,


    The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

    P L 2 Replies Last reply
    0
    • P Programm3r

      Hi all, How can I perform the following C++ structure code within C#?struct EmpStruct { char name[15]; char surname[15]; }EMP[100];
      Many thanks in advance Regards,


      The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

      P Offline
      P Offline
      Programm3r
      wrote on last edited by
      #2

      Is this correct:public struct EMP { public string name; public string surname; } .... EMP [] employee = new EMP[100]; ....
      Many thanks in advance Regards,


      The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

      V L 2 Replies Last reply
      0
      • P Programm3r

        Is this correct:public struct EMP { public string name; public string surname; } .... EMP [] employee = new EMP[100]; ....
        Many thanks in advance Regards,


        The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        (It is :) )

        Cheers, Vikram.


        The hands that help are holier than the lips that pray.

        P 1 Reply Last reply
        0
        • P Programm3r

          Is this correct:public struct EMP { public string name; public string surname; } .... EMP [] employee = new EMP[100]; ....
          Many thanks in advance Regards,


          The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

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

          Hi, there is a difference: in unmanaged C/C++ the struct EmpStruct has a size of 30 (or 32), since it contains 30 characters. your C# struct has a size of 8 (or 16 on Win64) since it contains two references and no characters. So it all depends what you are trying to do: - if you are porting a C/C++ app to C#, it could be good enough; - if you want your C# to cooperate with existing software or hardware that needs the original struct EmpStruct, then it is not OK, and you will need special Marshalling instructions. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          P 1 Reply Last reply
          0
          • V Vikram A Punathambekar

            (It is :) )

            Cheers, Vikram.


            The hands that help are holier than the lips that pray.

            P Offline
            P Offline
            Programm3r
            wrote on last edited by
            #5

            No, not yet ... but according to some code snippets I saw on the web it looks like it will work. Thanks for the response.


            The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

            1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, there is a difference: in unmanaged C/C++ the struct EmpStruct has a size of 30 (or 32), since it contains 30 characters. your C# struct has a size of 8 (or 16 on Win64) since it contains two references and no characters. So it all depends what you are trying to do: - if you are porting a C/C++ app to C#, it could be good enough; - if you want your C# to cooperate with existing software or hardware that needs the original struct EmpStruct, then it is not OK, and you will need special Marshalling instructions. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


              P Offline
              P Offline
              Programm3r
              wrote on last edited by
              #6

              Thanks for the response Luc, well I'm rewriting a application into C# from C++ .... so that is the only reason I was asking. Thanks again Regards,


              The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

              P 1 Reply Last reply
              0
              • P Programm3r

                Thanks for the response Luc, well I'm rewriting a application into C# from C++ .... so that is the only reason I was asking. Thanks again Regards,


                The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

                P Offline
                P Offline
                papadimitriou
                wrote on last edited by
                #7

                the structs are value types and classes are reference types.

                f(yf) = yf

                1 Reply Last reply
                0
                • P Programm3r

                  Hi all, How can I perform the following C++ structure code within C#?struct EmpStruct { char name[15]; char surname[15]; }EMP[100];
                  Many thanks in advance Regards,


                  The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  You are looking for FixedBufferAttribute[^]

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 3 out now

                  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