Rick Lones wrote:
TreeNodeTableItem tvi = _tabularView[i];
tvi.a = amount1;
tvi.b = amount2;
.. . . etc.
This saves an indexing step for each structure member access. Whether
it's noticeably faster for you depends on your usage, of course. This
looks like a pattern that a decent optimizer could recognize and handle
for you, though.
Posting late always bites me. But I think the code you suggested is
_required_ (sort of), since the List<type is a struct (value type).
That is, the indexer returns a copy of the value, not the indexed
element itself. So the only way to change the value within the list is
to initialize an existing value type variable with the desired values,
and then assign that to the indexed list item.
I wrote "sort of", because if one is overwriting all of the values in
the struct, obviously there's no point in retrieving the indexed list
item at the start (as in the assignment in the variable declaration in
the above code).
The code would make more sense as an _alternative_ rather than a
requirement if the list type was a class instead of a struct. Then the
value being returned by the indexer is the reference to the instance,
and the instance itself can be modified in-place without having to
reassign anything back to the list. And of course in that situation,
the assignment in the variable declaration is necessary.
Pete