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