我怎样才能var finalQuestions
从课堂问题到我的 GroupExmStart 表格string QuestionSet = "";
?如何在 Form 中获取它以及需要进行哪些转换才能将其存储为字符串?我想将它存储为字符串,因为这个 QuestionSet 我必须在这里传递:int z = Quiz(QuestionSet);
,我怎么能这样做?他们是我可以实现这一目标的更好方法吗?
GroupExmStart 表格
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];
for (int i = 0; i < 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;
}
}
课堂问题
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 from Questions where TopicID IN(" +
topicId + ") and 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 to be 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 I want to access in my Form
var finalQuestions = new List<Question>();
for (int i = 0; i < mark1qsn; i++)
{
var setIndex = _random.Next(mark1questionSet.Count);
finalQuestions.Add(mark1questionSet[setIndex]);
mark1questionSet.RemoveAt(setIndex);
}
for (int i = 0; i < mark2qsn; i++)
{
var setIndex = _random.Next(mark2questionSet.Count);
finalQuestions.Add(mark2questionSet[setIndex]);
mark2questionSet.RemoveAt(setIndex);
}
}
}