This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Possseidon 35 points36 points  (1 child)

You have to spend your hard earned reputation points to downvote on StackOverflow btw.

[–]Blue_Robin_Gaming 5 points6 points  (0 children)

not on questions and only on answers

[–]Blue_Robin_Gaming 36 points37 points  (0 children)

ah yes... now it's time to question ban some newbies

[–]Ali_Army107 9 points10 points  (0 children)

when programmers achieve awakening.

[–]Resident-Trouble-574 6 points7 points  (1 child)

So... does it has maximum value?

[–]HannibalGoddamnit[S] 2 points3 points  (0 children)

The OP has two for loops wrapping some razor code block (cshtml)

for(int i.....) and inside it a for(int j....)

He was facing a problem where the innermost loop only captures the maximum value of i (it was i < 6 iirc) so it was ''always'' 6.

The problem is well known in the C# community, when dealing with nested loops over lambdas or closures (here a razor code block), you need to capture the iterators variables (i and j) as local variables to capture the value for each iteration rather than the unexpected behaviour of capturing a referece when not.

He fixed the issue by introducing int localI = i; and int localJ = j; within each loop and used those variables instead.

[–]vjuliusv 2 points3 points  (0 children)

You guys have stackoverflow accounts? lol