Iterating through two lists of two inherited classes (of the same base class)
<p>I have two lists. The types of both lists inherit from the same base type. I want to iterate through them and do operations which only use functionality of the base class without having two basically identical foreach loops one after the other.</p>

<p>I can't copy the lists to another list or something of the sort, as I need to use the lists in their original form separately after the operation is complete.</p>

<p>Is there a way to do this without writing a function?</p>

<pre><code>class Program
{
    static void Main(string[] args)
    {
        // I have two lists of inherited classes
        List&lt;Babby1&gt; list1 = returnBabby1();
        List&lt;Babby2&gt; list2 = returnBabby2();

        // I want to iterate through both, and do the same thing, which is a part
        // of the base class functionality.
        // Basically I want this to be a single foreach loop.
        foreach (Babby1 item in list1)
            item.var = 50;

        foreach (Babby2 item in list2)
            item.var = 50;

        // I have to send them as separate lists, the type being the original (inherited) class
        sendBabby1(list1);
        sendBabby2(list2);
    }

    static void sendBabby1(List&lt;Babby1&gt; list)
    {
    }

    static void sendBabby2(List&lt;Babby2&gt; list)
    {
    }

    static List&lt;Babby1&gt; returnBabby1()
    {
        return new List&lt;Babby1&gt;();
    }

    static List&lt;Babby2&gt; returnBabby2()
    {
        return new List&lt;Babby2&gt;();
    }
}

class Base
{
    public int var;
}

class Babby1 : Base
{
    public int var1;
}

class Babby2 : Base
{
    public int var2;
}
</code></pre>
