C#动态数组(ArrayList )应用可以说在C#开发中是十分常用的,那么具体的实用实例是如何实现的呢?具体的实现步骤和注意事项是什么呢?
下面就是一个C#动态数组实例:用绑定一个DataList的三层代码
C#动态数组之DAL 数据访问层代码:
//绑定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;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
C#动态数组之BLL业务层代码:
//绑定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;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
C#动态数组之页面层代码:
//绑定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]);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
C#动态数组的应用实例就向你介绍到这里,希望对你了解和学习C#动态数组有所帮助。
【编辑推荐】