Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查查询响应c中是否存在字符串_C#_Linq - Fatal编程技术网

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

C# 检查查询响应c中是否存在字符串,c#,linq,C#,Linq,我从select查询中得到一个响应,并将它们存储到字符串列表中 string abc = "123"; List<string> numb = new List<string>(); string selectQuery = "SELECT Number FROM NumberList;"; using (MySqlConnection conn = new MySqlConnection(connStr))

我从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是否存在于numb中。我不想为此使用for循环,因为从查询响应返回的记录计数很高。是否有任何简单的方法可以检查123是否存在于列表中。

这是什么

if (numb.Contains(abc)) 
{
   // List contains the string contained in variable abc
}
这个

if (numb.Contains(abc)) 
{
   // List contains the string contained in variable abc
}

如果numb.Containsreader.GetString0{//是,它包含!}我需要检查numb是否包含字符串abcif numb.containsAbc但为什么要这样做?从NumberList中选择Number,其中Number=123将为您提供一条记录,如果123在数据库中,则为零。为什么要阅读所有内容然后扔掉呢?如果numb.Containsreader.GetString0{//是的,它包含!}我需要检查numb是否包含字符串abcif numb.containsAbc但为什么要这样做?从NumberList中选择Number,其中Number=123将为您提供一条记录,如果123在数据库中,则为零。为什么要把所有的东西都读了然后扔掉?