I'm currently making my own very basic generic list class (to get a better understanding on how the predefined ones work). Only problem I have is that I can't reach the elements inside the array as you normally do in say using "System.Collections.Generic.List
".
GenericList<type> list = new GenericList<type>();
list.Add(whatever);
This works fine, but when trying to access "whatever" I want to be able to write :
list[0];
But that obviously doesn't work since I'm clearly missing something in the code, what is it I need to add to my otherwise fully working generic class ?
GenericList
class look like? – Superciliouspublic void ActOnElement<TP1>(int index, ActByRef<T,TP1> proc, ref TP1 param1) { proc(ref Array[index], ref TP param1); }
which will allow code to act directly on a list item [assumepublic delegate void ActByRef<T1,T2>(ref T1 p1, ref T2 p2);
]. If one has e.g. aGenericList<Rectangle>
, such a method can allow code to saymyList.ActOnItem(index, (ref Rectangle r, ref int v) => {r.X -= v; r.Width+=v;}, ref widthAdjust)
to update a list item "in-place". – Burweed