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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Convert data type

Convert data type

Scheduled Pinned Locked Moved C#
csharphelpquestion
3 Posts 2 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.
  • H Offline
    H Offline
    Hoang Dung
    wrote on last edited by
    #1

    When I programed in C, I use memcpy function to change a struct to a string. Ex: struct A { int x; ... }; ... A a; char str[50]; memcpy(str,&a,sizeof(A)); ... However, when I write in C#, I also want to convert a class/struct to string but I don't. Can you help me? Thanks

    Z 1 Reply Last reply
    0
    • H Hoang Dung

      When I programed in C, I use memcpy function to change a struct to a string. Ex: struct A { int x; ... }; ... A a; char str[50]; memcpy(str,&a,sizeof(A)); ... However, when I write in C#, I also want to convert a class/struct to string but I don't. Can you help me? Thanks

      Z Offline
      Z Offline
      zuhx
      wrote on last edited by
      #2

      You can do it this way: A aa = new A(); string myString = aa.x.ToString();

      H 1 Reply Last reply
      0
      • Z zuhx

        You can do it this way: A aa = new A(); string myString = aa.x.ToString();

        H Offline
        H Offline
        Hoang Dung
        wrote on last edited by
        #3

        Thank you for your answer, but I want to convert a string to a class/struct because I write an application using Socket, Server module wrote in MFC 6.0 and client module I write in C#, data from Server send to Client are records which converted to string and pass throught metwork. Now, I want convert this data to struct/class after receive string data from server. Please help me. It very importance for me. Thanks.

        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