C# Problem with collection of custom classes
<p>In my application I have robots that the user can give any number of different tasks to do. Each task is a class derived from the abstract class Task:</p>

<pre><code>public abstract class Task
{
    string description = "default description";
    ...
}

public class Walk : Task
{
    string description = "Do walk";
    ...
}

public class Talk : Task
{
    string description = "Do talk";
    ...
}
</code></pre>

<p>So each robot has a collection of these tasks. The collection is defined like this:</p>

<pre><code>public class TaskCollection
{
    List&lt;Task&gt; _collection = new List&lt;Task&gt;();

    public void AddTask(string taskName)
    {
        _collection.Add( (Task)Activator.CreateInstance(null, taskName).Unwrap() );
    }

    public int Count()
    {
        return _collection.Count;
    }

    public Task GetElement( int i )
    {
        return _collection[i];
    }
}
</code></pre>

<p>So to test it out I create a TaskCollection and add some tasks like this:</p>

<pre><code>public TaskCollection tasks = new TaskCollection();
tasks.AddTask( "Walk" );
tasks.AddTask( "Talk" );
</code></pre>

<p>And then this code to show all the tasks that have been added:</p>

<pre><code>for( int i = 0; i &lt; tasks.Count(); i++ )
{
    print( tasks.GetElement(i).description );
}
</code></pre>

<p>For each task it prints out "default description" rather than the descriptions assigned in the inherited classes. Is this because i'm casting the class instance as a Task? If i remove that cast I get this error:</p>

<p>The best overloaded method match for `System.Collections.Generic.List.Add(Task)' has some invalid arguments.</p>

<p>Hopefully its clear what I'm trying to do here. Can anybody see where I'm going wrong?</p>
