Maintaining a single collection subdivided by a value's property I'm working on a networked game. In this game, the base entity is called an actor. An actor can either be replicated or local, with each instance having a "replicates" field that represents this.

When managing a scene, a collection of actor must be maintained. My problem is finding a suitable solution to this. Right now I store a collection of references to local actors, replicated actors and all actors. This means data is duplicated which results in code like this:

        for( int i = 0; i &lt; actorsToRemove.Count; ++i )
        {
            if( actorsToRemove[i].Replicates )
            {
                replicatedActors.Remove( actorsToRemove[i].Id );
            }
            else
            {
                localActors.Remove( actorsToRemove[i] );
            }
            allActors.Remove( actorsToRemove[i] );
        }
        actorsToRemove.Clear();


Instead of just removing from a single collection. 

I could have one single collection that holds all actors and use properties that return another collection. For example:

public List&lt;Actor&gt; ReplicatedActors
{
    get
    {
        // loop through all actors and return a new list that holds all replicating actors.
    }
}


But this seems like too much unnecessary copying.

What would be the best way to go about this?
What you suggested is absolutely fine. There isn't any unnecessary copying. Although, to make things simpler, I suggest using LINQ extension methods for filtering.

using System.Linq;

public IEnumerable&lt;Actor&gt; ReplicatedActors
{
    get { return allActors.Where(actor =&gt; actor.Replicates); }
}

public IEnumerable&lt;Actor&gt; LocalActors
{
    get { return allActors.Where(actor =&gt; !actor.Replicates); }
}


You'll still have to remove actors from allActors, these two are separate read-only lists of actors derived from the list of all actors.

Edit: I also suggest changing your actor removal loop to be a foreach loop for simplicity.

foreach (var actor in actorsToRemove)
{
    allActors.Remove(actor);
}
actorsToRemove.Clear();