Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I expose only a fragment of IList<>?

I have a class property exposing an internal IList<> through

System.Collections.ObjectModel.ReadOnlyCollection<>

How can I pass a part of this ReadOnlyCollection<> without copying elements into a new array (I need a live view, and the target device is short on memory)? I'm targetting Compact Framework 2.0.

like image 672
skolima Avatar asked Sep 02 '08 13:09

skolima


1 Answers

Try a method that returns an enumeration using yield:

IEnumerable<T> FilterCollection<T>( ReadOnlyCollection<T> input ) {
    foreach ( T item in input )
        if (  /* criterion is met */ )
            yield return item;
}
like image 98
Keith Avatar answered Oct 24 '22 21:10

Keith