I am using a ArrayList of struc “Osto”. I Unbox the values as I read from the ArrayList “List”. Struct “Osto” contains IOrders like Oe1, Oe2, Os1, Os2 and Ol1 along with other data types.
Now I like to change one element (Oe1) from a particular element (for instance say 2nd element) of the Arraylist “List”. I get an error message “Cannot modify the result of an unboxing conversation” near If-statement.
Do I have to remove the i th element, reconstruct it and then add it back to the “List”? Any simpler way of modifying just the particular inner element(Oe1)?
Many thanks in advance.
My Code:
// struc containing info of stops, limits, IOrders of Positions that opened at an instance
privatestruct Osto {publicdouble op;publicdouble st;public DateTime tm;public IOrder oe1;public IOrder oe2;public IOrder os1;public IOrder os2;public IOrder ot1;}
// Arraylist to store the data of Resistance, Support and Orders
private ArrayList Shortord = new ArrayList();
privateint Gono(IOrder Or, ArrayList List){
bool B1;
for (int i=0;i<List.Count;++i){
B1=(Or.Token==(((Osto)List[i]).oe1).Token);// OK
if(B1){
((Osto)List[i]).oe1=Or;// ERROR! I am assigning IOrder Or to i th element of List which is a struc of type Osto.
return i;
}
}
return0;
}
Comment