c# - 列表 C# 查找匹配的用户

标签 c# asp.net

我在 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/

相关文章:

c# - 如何使用 Linq 选择列名

C# - 动态关键字和接口(interface)实现

c# - Azure Functions 中的 HttpClient 最佳实践

c# - 函数参数中的列表文本框

c# - 在大型 Asp.net 应用程序中更改每个控件,如 TextBox 的最大长度

c# - 如何使用 CSP 全局管理员凭据在 Azure AD 中为我的租户注册应用程序?

c# - 按类型从表达式中提取所有条件

asp.net - 从代码隐藏启用兼容性 View (IE8)?

asp.net - ASP.NET Web 应用程序可以在没有 web.config 的情况下运行吗

c# - 由于我使用的是 mac,所以我在 azure data studio 中在哪里可以找到连接字符串,并且我将需要它