Replace LinkedList element value through LinkedList.Enumerator
- by Yan Cheng CHEOK
I realize there are no way for me to replace value through LinkedList.Enumerator. For instead, I try to port the below Java code to C#
// Java
ListIterator<Double> itr1 = linkedList1.listIterator();
ListIterator<Double> itr2 = linkedList2.listIterator();
while(itr1.hasNext() && itr2.hasNext()){
Double d = itr1.next() + itr2.next();
itr1.set(d);
}
// C#
LinkedList<Double>.Enumerator itr1 = linkedList1.GetEnumerator();
LinkedList<Double>.Enumerator itr2 = linkedList2.GetEnumerator();
while(itr1.MoveNext() && itr2.MoveNext()){
Double d = itr1.Current + itr2.Current;
// Opps. Compilation error!
itr1.Current = d;
}
Any other technique I can use?