Skip to main content
Post Undeleted by user33306
added 237 characters in body
Source Link
user33306
user33306

For example to only select a number that is larger than the previous one. I don't currently know of any LINQ method that would allow me to do such a thing

Actually there is a LINQ extension which allows you to do that. the Where extension has an overload that uses the item value and the item's index:

returnList<int> collectiontest1 = new List<int>()
{
    23,
    45,
    16,
    8,
    90,
    25
};
var test2 = test1.Where((x, i) => (i > 0)?x > collection[itest1[i - 1]:false);

One caveat to this is, it will only work for indexed collections of types that support comparison operators.

For example to only select a number that is larger than the previous one. I don't currently know of any LINQ method that would allow me to do such a thing

Actually there is a LINQ extension which allows you to do that. the Where extension has an overload that uses the item value and the item's index:

return collection.Where((x, i) => (i > 0)?x > collection[i - 1]:false);

For example to only select a number that is larger than the previous one. I don't currently know of any LINQ method that would allow me to do such a thing

Actually there is a LINQ extension which allows you to do that. the Where extension has an overload that uses the item value and the item's index:

List<int> test1 = new List<int>()
{
    23,
    45,
    16,
    8,
    90,
    25
};
var test2 = test1.Where((x, i) => (i > 0)?x > test1[i - 1]:false);

One caveat to this is, it will only work for indexed collections of types that support comparison operators.

Post Deleted by user33306
Source Link
user33306
user33306

For example to only select a number that is larger than the previous one. I don't currently know of any LINQ method that would allow me to do such a thing

Actually there is a LINQ extension which allows you to do that. the Where extension has an overload that uses the item value and the item's index:

return collection.Where((x, i) => (i > 0)?x > collection[i - 1]:false);