繁体   English   中英

无法转换类型为“ WhereSelectListIterator`2”的对象

[英]Unable to cast object of type 'WhereSelectListIterator`2

下面是我的代码。 try的行抛出以下错误

无法转换类型为“ WhereSelectListIterator 2[System.Tuple 3 [System.String,System.String,System.String],Syste> m.Boolean]”的对象来键入“ System.Tuple`3 [System.String,System。 String,System.String]'

为什么我无法按照以下方式进行投射? 我该怎么办?

        List<Tuple<string, string, string>> customers = new List<Tuple<string, string, string>>();
        customers.Add(new Tuple<string,string,string>("Saroj", "India", "Mumbai"));
        customers.Add(new Tuple<string, string, string>("Robin", "US", "New York"));

        List<string> filterNames = new List<string>();
        filterNames.Add("Saroj");

        foreach (string name in filterNames)
        {
            var customer = customers.Select(s => s.Item1 == name);
            try
            {
                Tuple<string, string, string> item = (Tuple<string, string, string>)customer;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }

您必须将其放到哪里,您将获得输出。无需投放。

foreach (string name in filterNames)
        {
            var customer = customers.Where(s => s.Item1 == name);
         }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM