protected void Page_Load(object sender, EventArgs e)
{
List<User> list = new List<User>();
list.Add(new User(1, "testOne"));
list.Add(new User(2, "testTwo"));
list.Add(new User(3, "testThree"));
list.Add(new User(4, "testTwo"));
User user1 = list.Find(p =>p.name.Equals("testTwo"));
string aa= list.Find((User uu) => uu.name.Equals("testTwo")).ToString();
List<User> listfind = list.FindAll(p => p.name == "testTwo");
for(int i=0;i<listfind.Count;i++)
{
Response.Write(listfind[i].id + "," + listfind[i].name + "<br>");
}
Response.Write("<br><br>");
int imatch = list.FindIndex(a => a.name == "testThree"); //查找是否存在叫"testThree"的人,返回list中有位置,注意:这里的位置并不是数据的id
Response.Write("所在位置为:"+imatch);
}
class User
{
int _id;
string _name;
public User(int id, string name)
{
_id = id;
_name = name;
}
public int id
{
set { _id = value; }
get { return _id; }
}
public string name
{
set { _name = value; }
get { return _name; }
}
}