例如
string[] s = {a,b,c,d}
a,b,c,d分别是string 类的变量,怎么样在更改s[i]的同时,对应的变量也随着被更改?

解决方案 »

  1.   

    s[0]="ttt";
    a="ttt";
    就这样改
      

  2.   

    是在一个类的构造函数里面,通过向数据库查询动态构造这个类的实例,而数组是我用来存放类中属性的容器,应为有多个属性,所以要向数据库做多个相似的查询,所以用for循环来操纵数组和查询语句,而数组中所包含的变量就是本类的属性,我知道用变量给数组元素赋值是传值调用,可是又不知道怎么做,所以才来问各位的 
      

  3.   

    这个是小弟的代码:using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;/// <summary>
    ///Question 的摘要说明
    /// </summary>
    public class Question
    {
    public Question()
    {
    //
    //TODO: 在此处添加构造函数逻辑
    //
    }    /// <summary>
        /// dynamic construct fuction
        /// </summary>
        /// <param name="w">the orm related to database</param>
        /// <param name="Subject_U">the table name</param>
        /// <param name="ID_U">the identity column</param>
        public  Question(WebExaminationDataContext w, string Subject_U,int ID_U ,int ID_I)
        {
            string [] s = {"QTitle","QA","QB","QC","QD","QKey"};
            string [] p = {Question_T ,CA ,CB ,CC ,CD ,Key };
            for (int i =0;i < s.Length ;i ++)
            {
                Set_U(w, Subject_U, ID_U, ref  p[i], s[i]);
            }
            ID = ID_I;
        }    /// <summary>
        /// dynamic get this class's property from the database
        /// </summary>
        /// <param name="w">the orm related to database</param>
        /// <param name="Subject_U">the table name</param>
        /// <param name="ID_U">the identity column</param>
        /// <param name="this_property">the property in this class</param>
        /// <param name="selecte_property">the column to be selected in table</param>
        protected void Set_U(WebExaminationDataContext w, string Subject_U, int ID_U, ref string this_property, string selecte_property)
        {
            var query = w.ExecuteQuery<string>("select " + selecte_property + " from " + Subject_U + " where QID = " + ID_U.ToString(), "");
            foreach (var q in query)
            {
                this_property = q.ToString();
            }
        }
        
        /// <summary>
        /// the id num of instanse
        /// </summary>
        public int ID
        {
            get;
            set;
        }    /// <summary>
        /// the question presentation
        /// </summary>
        public string Question_T
        {
            get;
            set;
        }
        /// <summary>
        /// the first choose
        /// </summary>
        public string CA
        {
            get;
            set;
        }
        public string CB
        {
            get;
            set;
        }
        public string CC
        {
            get;
            set;
        }
        public string CD
        {
            get;
            set;
        }
        /// <summary>
        /// the user's answer
        /// </summary>
        public string U_Key
        {
            get;
            set;
        }
        /// <summary>
        /// the right answer
        /// </summary>
        public string Key
        {
            get;
            set;
        }
        public bool IsRight
        {
            get;
            set;
        }
        /// <summary>
        /// check the user's answer is right or wrong
        /// </summary>
        public void Q_Check()
        {
            if (U_Key == Key)
                IsRight = true;
            else
                IsRight = false;
        }
    }