LINQ where vs takewhile

后端 未结 6 1352
感情败类
感情败类 2021-01-30 07:46

I want to get a difference between TakeWhile & Where LINQ methods .I got the following data from MSDN .But It didn\'t make sense to me

Where

        
6条回答
  •  没有蜡笔的小新
    2021-01-30 08:40

    Say you have an array that contains [1, 3, 5, 7, 9, 0, 2, 4, 6, 8]. Now:

    var whereTest = array.Where(i => i <= 5); will return [1, 3, 5, 0, 2, 4].

    var whileTest = array.TakeWhile(i => i <= 5); will return [1, 3, 5].

提交回复
热议问题