我在 ASP.NET 上有这个列表,我想找到从文本框中给出的 connectionid,找到匹配的用户,然后将他的昵称写到另一个文本框中。我怎样才能做到这一点?
static List<User> users = new List<User>();
class User
{
public string connectionid { get; set; }
public string nick { get; set; }
}
protected void Button2_Click(object sender, EventArgs e)
{
//I want to find connectionid from TextBox1, write the matching User nick into TextBox2
}
最佳答案
也许这会有所帮助。
foreach(User _user in users)
{
if(_user.connectionid == TextBox1.Text)
{
TextBox2.Text = _user.nick;
break;
}
}
更新
添加了 break 语句以在找到匹配项时退出循环。
关于c# - 列表 C# 查找匹配的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20448536/