I have the following method:private void removeUnnecessaryLines(List<ScatterViewItem> list){    List<Line> remove = new List<Line>();    foreach (Line line in lines)    {        SourceFile destination = (line.Tag as Call).getCallee();        foreach (ScatterViewItem svi in list)        {            SourceFile test = svi.Tag as SourceFile;            if (test.Equals(destination))            {                remove.Add(line);            }        }    }    foreach (Line l in remove)    {        lines.Remove(l);        Dependencies.Children.Remove(l);    }}As you can see, there is a lot of iteration and casting. Is there a simple way to improve that?
Loops for removing unnecessary lines
c#;casting
The most obvious improvement would be to use LINQ's Where method to filter the lines list instead of building up a list of to-be-deleted items and then deleting them. In addition to being easier to read and understand it will have the benefit of its runtime not being quadratic in the length of lines.You can also use the List<T>.RemoveAll method which also takes a predicate like Where (though the predicate specifies the items to be removed, so it's in a way the opposite of Where), but modifies the list in-place, like your solution did.