List has object which has properties as follows :
public class PropertyDetails
{
public int Sequence { get; set; }
public int Length { get; set; }
public string Type { get; set; }
public int Index { get; set; }
}
List will have sorted Sequence .
List has object values as follows:
Sequence= 1 Length=20 Type=”” Index=0
Sequence= 2 Length=8 Type=”” Index=0
Sequence= 3 Length=6 Type=”” Index=0
Sequence= 4 Length=20 Type=”” Index=0
Sequence= 5 Length=8 Type=”” Index=0
I want Linq query which will give me result List as
Sequence= 1 Length=20Type=”” Index=20
Sequence= 2 Length=8 Type=”” Index=28
Sequence= 3 Length=6 Type=”” Index=34
Sequence= 4 Length=20 Type=”” Index=54
Sequence= 5 Length=8 Type=”” Index=62
Where index is cumulative sum of Length considering sequence.
I never though I’d say this, but I find Jon’s solution to be overengineering. Rather, I find LINQ to be the wrong solution for this problem. You want to manipulate state, not a good fit for traditional LINQ-operators.
I’d just do this:
LINQ is a hammer. Make sure you use the right tool for the problem, instead of just asking for hammering-advice.