- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我正在处理尝试在自定义集合类中分块项目,该类在 C# 2.0 中实现了 IEnumerable(和 ICollection)。比方说,我一次只想要 1000 件元素,而我的收藏中有 3005 件元素。我有一个可行的解决方案,我在下面演示了它,但它看起来太原始了,我认为必须有更好的方法来做到这一点。
这是我所拥有的(例如,我使用的是 C# 3.0 的 Enumerable 和 var,只需将这些引用替换为您心中的自定义类):
var items = Enumerable.Range(0, 3005).ToList();
int count = items.Count();
int currentCount = 0, limit = 0, iteration = 1;
List<int> temp = new List<int>();
while (currentCount < count)
{
limit = count - currentCount;
if (limit > 1000)
{
limit = 1000 * iteration;
}
else
{
limit += 1000 * (iteration - 1);
}
for (int i = currentCount; i < limit; i++)
{
temp.Add(items[i]);
}
//do something with temp
currentCount += temp.Count;
iteration++;
temp.Clear();
}
谁能建议一种在 C# 2.0 中执行此操作的更优雅的方法?我知道如果这个项目是过去 5 年的项目,我可以使用 Linq(如 here 和 here 所示)。我知道我的方法会奏效,但我不想让我的名字与这种丑陋的(在我看来)代码相关联。
谢谢。
注意:这与 this other question 相似,但不完全相同 我已经实现了一个 IBusinessCollection界面。它来自 ICollection ,以及旧的非通用 ICollect
配置 AutoMapper 以映射的最佳/最简单方法是什么 ICollection至 ICollection至 ICollection ? 我有一个如下所示的 DomainModel: public
只想对syntactic sygar做简单的扩展: public static bool IsNotEmpty(this ICollection obj) { return ((obj !=
这个问题在这里已经有了答案: Why does IEnumerable inherit from IEnumerable? (4 个回答) 8年前关闭。 IEnumerable实现 IEnumerab
我正在尝试编写一个查询,从我的连接数据中获取国家列表。 Places是List . var zonedCountries = (from dz in db.DeliveryZones.
我有一组消息,每个消息定义为: namespace DatabaseDesign.Models { public class PrivateMessageDetail {
C# 中的 ICollection 中是否有一些方法可以添加另一个集合的所有元素?现在我必须始终为此编写 foreach 循环: ICollection allLetters = ... //some
转换 ICollection 的推荐方式是什么?至 ICollection其中 Bar工具 IBar ? 是不是就这么简单 collection = new List(); ICollection =
我用网格创建了表单来可视化任何集合( ICollection , ICollection )对象。 之后我创建了调试器可视化类(从 Microsoft.VisualStudio.DebuggerVis
我正在尝试基于 Stack 创建自定义集合.当我看 Stack [来自元数据] 在 Visual Studio 中,它显示 Stack实现 ICollection ,这将要求它实现 ICollecti
例如: public interface IFoo { //... ICollection Children { get; } //... } public class Foo
这个问题在这里已经有了答案: Why is it considered bad to expose List? [duplicate] (6 个答案) 关闭 9 年前。 我正在使用 FxCop 工具
这个问题在这里已经有了答案: Why does List implement IList, ICollection and IEnumerable? (4 个答案) 关闭 7 年前。 为什么ILis
我正在使用用 C# 创建的库。我一直致力于将一些代码移植到 F#,但必须使用 C# 库中的相当多的基础类型。 一段代码需要计算一个值列表并将其分配给类中的公共(public)字段/属性。该字段是一个包
此代码不起作用,但是: public virtual ICollection items { get { return (ICollection)items.Where(e => e.isVisibl
这个问题在这里已经有了答案: C# - sorting by a property (3 个答案) how to sort a collection by datetime in c# (4 个答案
这很奇怪,我试图在我的构造函数中使用 List 初始化我的 ICollection 并且发生了这种情况: Schedules = new List(); //OK CateringItems = ne
我想遍历设备上安装的所有语音。 在 TextSoSpeech 元数据中,我看到有 namespace Android.Speech.Tts { public class TextToSpeec
我有以下代码。为什么它总是采用“take(ICollection a)”方法?我认为它自己的对象应该是 LinkedList 或 HashSet,所以它应该调用另外两个 take 方法。 class
我的应用程序客户端/服务器有问题。我使用 MVVM 模式。在我看来,我有一个 DataGrid,它在我的 ViewModel 中与一个 ICollection 绑定(bind),代码行如下: publ
我是一名优秀的程序员,十分优秀!