不用循环和递归判断值在数组中的索引

不用循环和递归判断值在数组中的索引【原创】
2011-04-13 12:42

  ///////////////////////////////////////////////////////数组集合
                string[] str = new string[] { "a", "b", "c", "d", "e", "f", "g" };

                //////要查找的字符串
                string Num = "c";

                ///使用Linq查询,将索引和值查出来,
                ///新建一个匿名类,属性包括 aa bool类型,和 Index 索引
                var tt = str.Select((num, index) => new
                {
                    aa = (Num == num),
                    Index = index

                });
                //将得到的输出结果进行判断,查找 aa为true的索引值
                //最后成功得到它的索引
                int number = tt.Where(n => n.aa == true).Last().Index;

原文地址:https://www.cnblogs.com/joey0210/p/2014891.html