How to eliminate duplicate code?
<p>I have the following codes and I would like to write it in a way that I have minimum duplication of codes.</p>

<pre><code>if (Categories != null)
{
    bool flag=false;
    foreach (dynamic usableCat in Category.LoadForProject(project.ID))
    {
        foreach (dynamic catRow in Categories)
        {
            if (usableCat.ID == catRow.ID)
                flag = true;                            
        }
        if (!flag)
        {
            int id = usableCat.ID;
            Category resolution = Category.Load(id);
            resolution.Delete(Services.UserServices.User);
        }
    }
}
if (Priorities != null)
{
    bool flag = false;
    foreach (dynamic usableCat in Priority.LoadForProject(project.ID))
    {
        foreach (dynamic catRow in Priorities)
        {
            if (usableCat.ID == catRow.ID)
                flag = true;
        }
        if (!flag)
        {
            int id = usableCat.ID;
            Priority resolution = Priority.Load(id);
            resolution.Delete(Services.UserServices.User);
        }
    }
}
</code></pre>

<p>Please note that Category and priority do not have a common base type or interface that includes ID.</p>
