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. structure problem in c#

structure problem in c#

Scheduled Pinned Locked Moved C#
csharphelpquestion
9 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.
  • R Offline
    R Offline
    rjkg
    wrote on last edited by
    #1

    what is the equivalent of following C structure in c# struct mystructure { int number; char name[256]; };

    Rajesh

    L T 2 Replies Last reply
    0
    • R rjkg

      what is the equivalent of following C structure in c# struct mystructure { int number; char name[256]; };

      Rajesh

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

      Hi, it depends on what you want it for. If it's just data being shared between two pieces of C# code, then use:

      struct myStructure {
      int number;
      string name;
      }

      and it will hold your data, whatever the length of the name string will be. If on the other hand you want to share the data with code in another programming language, or with a hardware device, then it will take more effort (e.g.with Marshaling attributes or code) to match the requirements. :)

      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.


      R 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, it depends on what you want it for. If it's just data being shared between two pieces of C# code, then use:

        struct myStructure {
        int number;
        string name;
        }

        and it will hold your data, whatever the length of the name string will be. If on the other hand you want to share the data with code in another programming language, or with a hardware device, then it will take more effort (e.g.with Marshaling attributes or code) to match the requirements. :)

        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.


        R Offline
        R Offline
        rjkg
        wrote on last edited by
        #3

        actually i am writing some fields from webpages to file using structure. then I read the file using same structure in the c++ programme . in c++ no string data type so I cannot use string in my structure

        Rajesh

        A L G 3 Replies Last reply
        0
        • R rjkg

          actually i am writing some fields from webpages to file using structure. then I read the file using same structure in the c++ programme . in c++ no string data type so I cannot use string in my structure

          Rajesh

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          No string data type? But then what this: http://en.wikipedia.org/wiki/String_(C%2B%2B)[^] Thats assuming you can include <string>

          My current favourite word is: Bacon!

          -SK Genius

          R 1 Reply Last reply
          0
          • R rjkg

            actually i am writing some fields from webpages to file using structure. then I read the file using same structure in the c++ programme . in c++ no string data type so I cannot use string in my structure

            Rajesh

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

            Three comments then: so it is a binary file (because of the int) although probably most of the data is text? I would make it all text then (hence use int.ToString and/or int.TryParse) are you aware of character sizes? in C/C++ it could be 8-bit or 16-bit, on C# it will be 16-bit. Some people would recommend using XML for something like this. I'm still undecided. :)

            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.


            1 Reply Last reply
            0
            • A Anthony Mushrow

              No string data type? But then what this: http://en.wikipedia.org/wiki/String_(C%2B%2B)[^] Thats assuming you can include <string>

              My current favourite word is: Bacon!

              -SK Genius

              R Offline
              R Offline
              rjkg
              wrote on last edited by
              #6

              I am c# programmer and c++ site cannot change .it is already running and cannot change huge code there.

              Rajesh

              A 1 Reply Last reply
              0
              • R rjkg

                I am c# programmer and c++ site cannot change .it is already running and cannot change huge code there.

                Rajesh

                A Offline
                A Offline
                Anthony Mushrow
                wrote on last edited by
                #7

                Fair enough then.

                My current favourite word is: Bacon!

                -SK Genius

                1 Reply Last reply
                0
                • R rjkg

                  actually i am writing some fields from webpages to file using structure. then I read the file using same structure in the c++ programme . in c++ no string data type so I cannot use string in my structure

                  Rajesh

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  You can use a BinaryWriter to write the data to the file. The .NET equivalent of a C++ char is a byte. If you have text to put in the file, you have to know what encoding to use to turn it into an array of bytes.

                  Despite everything, the person most likely to be fooling you next is yourself.

                  1 Reply Last reply
                  0
                  • R rjkg

                    what is the equivalent of following C structure in c# struct mystructure { int number; char name[256]; };

                    Rajesh

                    T Offline
                    T Offline
                    Thomas Stockwell
                    wrote on last edited by
                    #9

                    structure mystructure { int number; string name; } The default for those variables in C# will be private (I believe), you will have to create properties to expose the variables.

                    Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

                    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