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. casting struct to list<object></object>

casting struct to list<object></object>

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    manowj
    wrote on last edited by
    #1

    Hi Everyone, I have placed a sample code below in which i need to type cast from struct to list. In this below example how i can add emp1 to operation list public struct Operation { public bool success; public string msg; public List<Object> ListTest; } public struct Emp { public int EmpID; public string EmpName; } public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public void Method1() { Emp emp1 = new Emp(); Operation op = new Operation(); emp1.EmpID = 1; emp1.EmpName = "Manoj"; op.success = true; op.msg = "pass"; op.ListTest.Add(emp1); } }

    Regards, Manowj

    OriginalGriffO 1 Reply Last reply
    0
    • M manowj

      Hi Everyone, I have placed a sample code below in which i need to type cast from struct to list. In this below example how i can add emp1 to operation list public struct Operation { public bool success; public string msg; public List<Object> ListTest; } public struct Emp { public int EmpID; public string EmpName; } public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public void Method1() { Emp emp1 = new Emp(); Operation op = new Operation(); emp1.EmpID = 1; emp1.EmpName = "Manoj"; op.success = true; op.msg = "pass"; op.ListTest.Add(emp1); } }

      Regards, Manowj

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      And your problem is? Looking at it, you are getting a "object not set to an instance of an object" exception, I suspect. Try:

      {
      Emp emp1 = new Emp();
      Operation op = new Operation();
      op.ListText = new List<object>();
      emp1.EmpID = 1;
      emp1.EmpName = "Manoj";
      op.success = true;
      op.msg = "pass";
      op.ListTest.Add(emp1);
      }

      Or, by preferance, convert it to a class and handle it's internals better yourself! BTW: use <pre> and </pre> blocks to preserve your formatting in future. It isn't too bad with a tiny fragment like this, but later...

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        And your problem is? Looking at it, you are getting a "object not set to an instance of an object" exception, I suspect. Try:

        {
        Emp emp1 = new Emp();
        Operation op = new Operation();
        op.ListText = new List<object>();
        emp1.EmpID = 1;
        emp1.EmpName = "Manoj";
        op.success = true;
        op.msg = "pass";
        op.ListTest.Add(emp1);
        }

        Or, by preferance, convert it to a class and handle it's internals better yourself! BTW: use <pre> and </pre> blocks to preserve your formatting in future. It isn't too bad with a tiny fragment like this, but later...

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        M Offline
        M Offline
        manowj
        wrote on last edited by
        #3

        Hi, Thanks for your response. how can this be converted to JSON using ExtJS, json serializer is not able to convert it.

        Regards, Manowj

        modified on Thursday, November 5, 2009 7:14 AM

        OriginalGriffO 1 Reply Last reply
        0
        • M manowj

          Hi, Thanks for your response. how can this be converted to JSON using ExtJS, json serializer is not able to convert it.

          Regards, Manowj

          modified on Thursday, November 5, 2009 7:14 AM

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          I wouldn't want to convert it to anorexic XML. Edit your OP to correct the code, and reflect the JSON requirement - you may get a more helpful resonse.

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          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