c# - How to get List data from class to Form -
how can var finalquestions
class question groupexmstart form in string questionset = "";
? how can in form , conversions need store string? want store string because questionset have pass here: int z = quiz(questionset);
,how this? better way can achieve this?
groupexmstart form
public partial class groupexmstart : form { string questionset = ""; public groupexmstart(string groupname, string durationid) { initializecomponent(); this.grpid=groupname; topiid=db.gettopicidforgroup(grpid); question qsn = new question(); string[] conf = db.getconfiguration(convert.toint16(durationid)).split('|'); qsn.foo(topiid, conf); int z = quiz(questionset); } int quiz(string data) { string[] words = data.split('$'); randomqsn = new string[totqsn + 1]; qanda = new string[words.length + 1]; (int = 0; < words.length; i++) { qanda[i] = words[i]; } return 0; } private void question(string id, string q, string op1, string op2, string op3, string op4) { label5.text = q; radiobutton12.text = op4; radiobutton11.text = op4; radiobutton10.text = op4; radiobutton9.text = op4; } }
class question
public class question { public string id { get; set; } public string text { get; set; } public string option1 { get; set; } public string option2 { get; set; } public string option3 { get; set; } public string option4 { get; set; } public string answeroption { get; set; } public int marks { get; set; } random _random = new random(); public ienumerable<question> getquestions(string topicid, int marks) { string sql = "select qid,question,opt1,opt2,opt3,opt4,ansop,marks questions topicid in(" + topicid + ") , marks=" + marks.tostring(); var cmd = new oledbcommand(sql,acccon); var rs = cmd.executereader(); if (rs != null) { while (rs.read()) { yield return new question { id = rs[0].tostring(), text = rs[1].tostring(), option1 = rs[2].tostring(), option2 = rs[3].tostring(), option3 = rs[4].tostring(), option4 = rs[5].tostring(), answeroption = rs[6].tostring(), marks = marks }; } } } public void foo(string topicid,string[] conf) { var totqsn = convert.toint16(conf[0]); var mark1qsn = convert.toint16(conf[3]); //this variable contains number of question display of mark 1 var mark2qsn = convert.toint16(conf[4]); var mark3qsn = convert.toint16(conf[5]); var mark4qsn = convert.toint16(conf[6]); var mark1questionset = getquestions(topicid, 1).tolist(); var mark2questionset = getquestions(topicid, 2).tolist(); //this finalquestions want access in form var finalquestions = new list<question>(); (int = 0; < mark1qsn; i++) { var setindex = _random.next(mark1questionset.count); finalquestions.add(mark1questionset[setindex]); mark1questionset.removeat(setindex); } (int = 0; < mark2qsn; i++) { var setindex = _random.next(mark2questionset.count); finalquestions.add(mark2questionset[setindex]); mark2questionset.removeat(setindex); } } }
have method foo return final questions variable...
public list<question> foo(string topicid, string[] conf) { // same stuff... return finalquestions; }
then, in groupexmstart method following...
question qsn = new question(); string[] conf = db.getconfiguration(convert.toint16(durationid)).split('|'); questionset = string.join(",", qsn.foo(topiid, conf)); int z = quiz(questionset);
edit per comment #1
a better way, imo, not join them begin with; , pass list of questions quiz method directly. have alter quiz method take list of questions like:
int quiz(list<question> questions)
and remove string.join above.
question qsn = new question(); string[] conf = db.getconfiguration(convert.toint16(durationid)).split('|'); var questions = qsn.foo(topiid, conf); int z = quiz(questions);
edit per comment #3
private void question(question q) { label5.text = string.format("{0} {1}", q.id, q.text); radiobutton12.text = q.option1; radiobutton11.text = q.option2; radiobutton10.text = q.option3; radiobutton9.text = q.option4; }
Comments
Post a Comment