Ilist Introductions and simple code

;IEnumerable, IEnumerable

using System.Collections.Generic;

The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.

Here is a simple code which could help better understand the IList interface

Userful Links

first create a UserInfo class

public class UserInfo

{

private string _userName = string.Empty;

private string _password = string.Empty;

public UserInfo()

{

//

// TODO: Add constructor logic here

//

}

public UserInfo(string userName, string password)

{

this._userName = userName;

this._password = password;

}

public string UserName

{

get { return _userName;}

}

public string Password

{

get { return _password; }

}

}

Then at main page, add a gridview to databind the IList result.
create a DataBind method
public DataBind()
{
IList<UserInfo> userinfos=new IList();
for(i=0;i<5,i++)
{
UserInfo newuinfo=new(“username”+i.ToString,”password”+i.TosString());
userinfos.Add(newuinfo);
//adding the conent into uinfo
}
this.Gridview1.datasource=useinfos;
this.Gridview1.databind();
}
At pageLoad  method
{
if (!page.Ispostback)
{
Databind();
}
}
So, the result is pretty much like this::

ilist1

~ by kimialex92 on 2009/03/19.

Leave a Reply