-2

我知道如何将数据从一个表单传递到另一个表单,但是我如何将数据从一个表单传递到类。这是我想传递form1给课堂问题的数据:

string GrpID = "somevalue";
string DurationID = "somevalue";`

我搜索了它,但我没有得到确切的答案。

class Question
{
    string GroupID="here i want this value of GroupID,how can i get this";
    string DuraID="and here value of DurationID";

    // so that i can use them here like this
    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, new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb"));
        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()//In this function Can i pass that `string[] conf` here?
        {
            var totQsn = Convert.ToInt16(conf[0]); // isn't this just the sum of everything else?
            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();
           }
4

1 回答 1

0

在类中添加一个方法:

class Question
{

   public void SomeFunction(string grpId, string durationId)
   {
        ...
   }

}

然后你可以从你的表单中调用它:

questionInstance.SomeFunction("somevalue","somevalue");
于 2013-08-07T10:48:30.580 回答