Can I have fixed typed ArrayList in C#, just like C++?
- by Kazoom
I have an ArrayList which contains fixed type of objects.
However everytime I need to extract an object a particular index, I need to typecast it to my user defined type from object type.
Is there a way in C# to declare ArrayList of fixed types just like Java and C++, or is there a work around to avoid the typecasting everytime?
Edit:
I apologize I forgot mentioning that I require the datastructure to be thread-safe, which List is not. Otherwise I would have just used a normal Array. But I want to save myself from the effort of explicitly locking and unlocking while writing the array.
So I thought of using ArrayList, synchronize it, but it requires typecasting every time.