Question: I have the following class:

```
public class Example(

   private String id;
   private ArrayList<String> docs = new ArrayList();

   public Example(string startid){
      id = startid;
      docs = null;
   }

   public void myMethod(String externalID){

      Example myExample = new Example(externalID);

}

```

If I understand well when I call myMethod, it will create an instance of Example called myExample with id = externalID and docs = null.

What I want this class to do is:
Call myMethod simultaneously from external points that will create an instance (myExample) and make sure that the external calls cannot overwrite any of myExample's variables (thread safe?)
What I also want it to do is to populate the docs array from an external call within the appropriate myExample instance. Is this possible at all or do I have to pass the ArrayList with the startid at the same time?

Answer: 
You can use a `List<T>` but keep it ordered. Use the [BinarySearch](http://msdn.microsoft.com/en-gb/library/w4e7fxsh.aspx) method to find your start `DateTime` within the list. Note that it returns:

> 
> The zero-based index of item in the sorted List, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count.
> 
> 
> 

So if the value is negative you will need to apply a bitwise complement (`~` operator) to find the first index that is within range. You can then use the same process and subtract 1 to find the last element within range.
Using LINQ (as this is one of your tags), you can do it like this:

```
IEnumerable<DateTime> orderedDateTimes; // Your ordered DateTime collection
DateTime start;     // The start date/time, inclusive
DateTime end;       // The end date/time, inclusive

var range = orderedDateTimes
            .SkipWhile(dt => dt < start)
            .TakeWhile(dt => dt <= end);

```

This will take *O(n)* worst case to get a range. However, you can force the result into a list or array to be able to reuse it efficiently:

```
DateTime[] rangeArray = range.ToArray();
// -or-
List<DateTime> rangeList = range.ToList();

```