首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Linq Where有关问题

2013-08-01 
Linq Where问题public static void Linq5(){string[] digits { zero, one, two, three, four,

Linq Where问题


        public static void Linq5()
        {
            string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; 
            var shortDigits = digits.Where((digit, index) => digit.Length < index); 
            Console.WriteLine("Short digits:");
            foreach (var d in shortDigits) 
            { 
                Console.WriteLine("The word {0} is shorter than its value.", d); 
            }
        }
//会打印出
//The word five is shorter than its value.
//The word six is shorter than its value.
//The word seven is shorter than its value.
//The word eight is shorter than its value.
//The word nine is shorter than its value.

求给解释一下工作原理和运行顺序。
digit.Length < index 这地方不太理解 感觉Length应该是10呀 LINQ C#
[解决办法]
引用:

        public static void Linq5()
        {
            string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; 
            var shortDigits = digits.Where((digit, index) => digit.Length < index); 


            Console.WriteLine("Short digits:");
            foreach (var d in shortDigits) 
            { 
                Console.WriteLine("The word {0} is shorter than its value.", d); 
            }
        }
//会打印出
//The word five is shorter than its value.
//The word six is shorter than its value.
//The word seven is shorter than its value.
//The word eight is shorter than its value.
//The word nine is shorter than its value.


求给解释一下工作原理和运行顺序。
digit.Length < index 这地方不太理解 感觉Length应该是10呀


 digits 是数组,所以长度是10,但是,
 digit  是数组中每个元素了

热点排行