无法转换'WhereSelectListIterator`2类型的对象

时间:2014-05-30 05:30:21

标签: c#

以下是我的代码。 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);
            }
        }

1 个答案:

答案 0 :(得分:0)

你必须放在哪里,你将得到你的输出。不需要施放。

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