How can I take the contents of a C# class and put into / take out of a string? -
i have following 2 classes:
public class testquestionmodel { public testquestionmodel() { this.answers = new list<testquestionanswermodel>(); } public int testid { get; set; } public int testquestionid { get; set; } public int questionnumber { get; set; } public virtual icollection<testquestionanswermodel> answers { get; set; } } public class testquestionanswermodel { public int answeruid { get; set; } public bool? correct { get; set; } public bool? response { get; set; } public string text { get; set; } }
what store answers string , put class:
public class testquestion { public int testid { get; set; } public int testquestionid { get; set; } public int questionnumber { get; set; } public string answerstring { get; set; } }
can tell me how can in both directions (putting in string , taking out)
possible way:
public string serialize(icollection<testquestionanswermodel> answers) { javascriptserializer serializer = new javascriptserializer(); return serializer.serialize(answers); } public icollection<testquestionanswermodel> deserialize(string data) { javascriptserializer serializer = new javascriptserializer(); return (icollection<testquestionanswermodel>)serializer.deserialize<icollection<testquestionanswermodel>>(data); }
Comments
Post a Comment