Y at-il une syntaxe LINQ pour les (T, int) Où et de surcharge Select?
-
04-10-2019 - |
Question
La requête
var q = from elem in collection
where someCondition(elem)
select elem;
se traduit
var q = collection.Where(elem => someCondition(elem));
Y at-il une syntaxe LINQ qui se traduirait par ce qui suit?
var q = collection.Where((elem, index) => someCondition(elem, index));
La solution
Non il n'y a pas de syntaxe LINQ pour cela.
Un travail autour simple pourrait être:
var q = from elem in collection.Select((x,i) => new {x,i})
where someCondition(elem.x,elem.i)
select elem.x;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow