我怎么能只暴露的IList℃的片段;&GT ;? [英] How can I expose only a fragment of IList<>?

查看:100
本文介绍了我怎么能只暴露的IList℃的片段;&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类财产公开内部的IList<通过

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

System.Collections.ObjectModel.ReadOnlyCollection<>



我如何能够通过这项工作的一部分 ReadOnlyCollection还<> 而不复制元素融入到一个新的数组(我需要现场查看,与目标设备短内存)? 。我打靶Compact Framework 2.0的

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.

推荐答案

尝试返回枚举使用产率的方法:

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;
}

这篇关于我怎么能只暴露的IList℃的片段;&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆