检查查询响应中是否存在字符串c#

时间:2017-03-08 21:55:01

标签: c# linq

我从select查询中获得响应并将它们存储到字符串列表中

        string abc = "123";
        List<string> numb = new List<string>();
        string selectQuery = "SELECT Number FROM NumberList;";
        using (MySqlConnection conn = new MySqlConnection(connStr))
        using (MySqlCommand cmd = new MySqlCommand(selectQuery, conn))
        {
            conn.Open();
            var reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                numb.Add(reader.GetString(0));
            }

我不知道如何检查麻木中存在的字符串abc。我不想为此使用for循环,因为从查询响应返回的记录数很高。是否容易检查列表中是否存在123。

2 个答案:

答案 0 :(得分:2)

此?

CREATE TABLE fakehours AS
WITH hours AS (
SELECT * FROM UNNEST(SEQUENCE(0,23,1)) AS t (hour)
)
SELECT   * 
FROM hours
;

答案 1 :(得分:0)

while (reader.Read())
{
    var s = reader.GetString(0);
    if (!numb.Contains(s))
    {
        numb.Add(s);
    }
}