What I need is something like an array but letting me to assign an element to whatever an index at any time and check if there is already a value assigned to particular index approximately like
MyArray<string> a = new MyArray<string>();
a = "ten";
bool isTheFifthElementDefined = a != null; // false
As you mentioned
Dictionary seems more appropriate for this.But you can do it with generic lists,for example, when you are creating your list you can specify an element count,and you can give a default temporary value for all your elements.
List<string> myList = new List<string>(Enumerable.Repeat("",5000)); myList = "bla bla bla..";
List<int> myList = new List<int>(Enumerable.Repeat(0,5000));
List<MyClass> myList = new List<MyClass>(Enumerable.Repeat(new MyClass(), 100));
Ofcourse It is not the best solution...
Note: Also you can use
SortedList instead of
Dictionary if you want an ordered collection by keys:
SortedList<TKey, TValue>: Represents a collection of key/value pairs that are sorted by key based on the associated IComparer implementation.