I tend to use ArrayLists of structures. It is then very easy to cycle through the list with a foreach.
The problem I have is I cant use a foreach to modify the structures contents and have to use a for and messy typecasts.
((dataStructure)files[x]).name = here;
Is there a tidier way to do it?
I know this sounds simplistic but just say no to mutable value types.
They’re almost never the right solution to the problem. There are a very few exceptions, but classes are almost always the way to go.
In addition, if you’re really using an
ArrayListthen you’ll be incurring an unboxing cost already… (As Konrad says, if you can use .NET 2.0 then use generics.)If you really insist on using mutable structures, then use a
forloop instead offoreach. But please, please change to classes anyway.