zoukankan      html  css  js  c++  java
  • ConcurrentDictionary<string, ConcurrentQueue<string>> 1个key 对应多个value

    如上图,需要将 groups的值作为key,将id 作为value 进行存放,生成一个键值对。

    string sqlConn = "Data Source=127.0.0.1;Initial Catalog=数据库ming;User ID=用户名;Password=密码";
                using (SqlConnection conn = new SqlConnection(sqlConn))
                {
                    conn.Open();//打开通道,建立连接,可能出现异常,使用try catch语句
                    SqlCommand cmd = conn.CreateCommand();
                    string getIds = @"select id,groups from XXX";
                    cmd.CommandText = getIds;
                    SqlDataReader read = cmd.ExecuteReader();
    
                    List<string> ids = new List<string>();
                    while (read.Read())
                    {
                        ConcurrentQueue<string> co = IdsList.GetOrAdd(read["groups"].ToString(), new ConcurrentQueue<string>());
                        co.Enqueue(read["id"].ToString());
                    }
                    read.Close();               
                }

    这样就可以得到结果。

  • 相关阅读:
    DNS服务器原理简述、搭建主/从DNS服务器并实现智能解析
    JQuery02
    JQuery01
    python05
    python04
    python03
    Liunx命令
    Python运算符及注释
    python01
    原生JDBC+mybatis
  • 原文地址:https://www.cnblogs.com/hllxy/p/12171648.html
Copyright © 2011-2022 走看看