C#動(dòng)態(tài)數(shù)組實(shí)用實(shí)例解析
C#動(dòng)態(tài)數(shù)組(ArrayList )應(yīng)用可以說在C#開發(fā)中是十分常用的,那么具體的實(shí)用實(shí)例是如何實(shí)現(xiàn)的呢?具體的實(shí)現(xiàn)步驟和注意事項(xiàng)是什么呢?
下面就是一個(gè)C#動(dòng)態(tài)數(shù)組實(shí)例:用綁定一個(gè)DataList的三層代碼
C#動(dòng)態(tài)數(shù)組之DAL 數(shù)據(jù)訪問層代碼:
- //綁定IDList,顯示所有人員列表
 - public DataSet SelectIDListAll()
 - {
 - string Str = "select p_number,p_name from t_people";
 - DataSet ds = new DataSet();
 - myCon = new SqlConnection(DAL.DALConfig.ConnectionString);
 - try
 - {
 - SqlDataAdapter mycomm = new SqlDataAdapter(Str,myCon);
 - mycomm.Fill(ds,"t_people");
 - return ds;
 - }
 - catch(Exception exc)
 - {
 - throw exc;
 - }
 - }
 
C#動(dòng)態(tài)數(shù)組之BLL業(yè)務(wù)層代碼:
- //綁定IDList,顯示所有人員列表
 - public ArrayList SelectIDListAll()
 - {
 - DAL.TPeopleDao peopledao = new TPeopleDao();
 - DataSet ds = new DataSet();
 - ds = peopledao.SelectIDListAll();
 - // Creates and initializes a new ArrayList.
 - ArrayList myAL = new ArrayList();
 - for(int i=0;i<ds.Tables[0].Rows.Count;i++)
 - {
 - myAL.Add(ds.Tables[0].Rows[i][0].ToString() +
 - " " +ds.Tables[0].Rows[i][1].ToString() );
 - }
 - return myAL;
 - }
 
C#動(dòng)態(tài)數(shù)組之頁面層代碼:
- //綁定IDList,顯示所有人員列表
 - private void SelectIDListAll()
 - {
 - Lab.BLL.TPeopleBiz peoplebiz = new TPeopleBiz();
 - ArrayList myAL = peoplebiz.SelectIDListAll();
 - this.P_IDlist.Items.Clear();
 - for(int i = 0 ;i<myAL.Count;i++)
 - {
 - this.P_IDlist.Items.Add(myAL[i]);
 - }
 - }
 
C#動(dòng)態(tài)數(shù)組的應(yīng)用實(shí)例就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#動(dòng)態(tài)數(shù)組有所幫助。
【編輯推薦】















 
 
 
 
 
 
 