Making a Function to Count Elements In Multiple Arrays
<p>Hullo,</p>

<p>For some reason (that I can't work out) a function that returns an ilist keeps returning null when I call it (even though earlier in the same method it returns an empty ilist, but whatever) so I was making a function to take in several ilists and then output the total number of elements across all the lists (ignoring the null ones as to avoid an exception).</p>

<p>So far I have:</p>

<pre><code>private int TotalItemsInLists(params IList[] lists)
    {
        int total = 0;


        foreach (IList list in lists)
            if (list != null)
                total += list.Count;

        return total;
    }
</code></pre>

<p>but that causes problems in that <code>params IList[] lists</code> doesn't seem to be called correctly, as the ILists are all lists of different types.</p>

<p>Anyone know how I can remedy this problem?</p>

<p>Thanks,
Harry</p>

<p>Edit: Here is the code that calls it</p>

<pre><code>private bool TooManyItems(Person person)
    {
        return TotalItemsInLists(jobService.BeingDevelopedBy(person), jobService.BeingTestedBy(person),
                                 jobService.BeingFixedBy(person), quoteService.BeingProducedBy(person),
                                 ticketService.BeingActivelyHandledBy(person),
                                 ticketService.BeingTestedBy(person),
                                 ticketService.AllAvailable(person)) &gt; 10;
    }
</code></pre>

<p>And here's an example of one of the methods they call (they're all pretty similar, just different databases and filters)</p>

<pre><code>public IList&lt;Ticket&gt; BeingActivelyHandledBy(Person person)
    {
        return (from ticket in Query()
                where ticket.Handler == person
                      &amp;&amp; ticket.Status == TicketStatus.Open
                      &amp;&amp; ticket.Release == null
                select ticket).ToList();
    }
</code></pre>
