what is the pattern for modifying a collection in C#
Posted
by macias
on Stack Overflow
See other posts from Stack Overflow
or by macias
Published on 2010-03-12T12:03:55Z
Indexed on
2010/03/12
12:07 UTC
Read the original article
Hit count: 257
What is the pattern (best practice) for such problem -- modifying elements (values) in collection?
Conditions:
- size of the collection is not changed (no element is deleted or added)
- modification is in-place
In C++ it was easy and nice, I just iterated trough a collection and changed the elements. But in C# iterating (using enumerator) is read-only operation (speaking in terms of C++, only const_iterator is available).
So, how to do this in C#?
Example: having sequence of "1,2,3,4" modification is changing it to "1, 2, 8, 9" but not "1, 2, 3" or "1, 2, 3, 4, 5".
© Stack Overflow or respective owner