C# 如何在指定索引处将ItemCollection拆分为2?

C# 如何在指定索引处将ItemCollection拆分为2?,c#,.net,wpf,linq,itemcollection,C#,.net,Wpf,Linq,Itemcollection,这似乎是一件非常基本的事情,但我找不到任何方法来做到这一点。我查过Intellisense,搜索过谷歌,但运气不好 我有一个ItemCollection,里面有大约30个项目。我正试图让前14项保留在原始的ItemCollection中,后16项(或无论多少项)移动到新的ItemCollection 我该怎么做myVar.CopyTo()可以,但是没有要复制的项目数的参数,它只接受一个数组作为输出。在myVar.RemoveAt()上循环似乎很昂贵。有内置的方法吗?是否可以使用Linq?如果可以

这似乎是一件非常基本的事情,但我找不到任何方法来做到这一点。我查过Intellisense,搜索过谷歌,但运气不好

我有一个
ItemCollection
,里面有大约30个项目。我正试图让前14项保留在原始的
ItemCollection
中,后16项(或无论多少项)移动到新的
ItemCollection


我该怎么做
myVar.CopyTo()
可以,但是没有要复制的项目数的参数,它只接受一个
数组作为输出。在
myVar.RemoveAt()上循环似乎很昂贵。有内置的方法吗?是否可以使用Linq?

如果可以将
ItemCollection
转换为
ArrayList
;然后你可以试试这个:

arraylist.RemoveRange( x, y );
这将删除从索引
x
开始的
y
元素

最后,您可以将
ArrayList
转换回
ItemCollection


如果集合中的项目太多,这将非常有用。

这就是我在
Print
类中完成的工作:

var Data = ...; // The original ItemCollection
var DataExcess = new DataGrid().Items; // It isn't possible to use new ItemCollection();

for(var i = 0; i < Data.Count; i++) {
    if(i > 13) {
        DataExcess.Add(Data[i]);
        continue;
    }

    // Otherwise print the row to the page using e.Graphics.DrawString(..)
}

if(DataExcess.Count > 0) {
    new Print(Some, Parameters, Here, ..., DataExcess).Print();
}
var数据=…;//原始项目集合
var dataoverse=new DataGrid().Items;//无法使用new ItemCollection();
对于(var i=0;i13){
添加(数据[i]);
继续;
}
//否则,使用e.Graphics.DrawString(..)将行打印到页面
}
如果(DataOverse.Count>0){
新打印(部分,参数,此处,…,DataOverse).Print();
}

你怎么能创建ItemCollection实例呢?@helb它最初来自一个
DataGrid
Items
,但通过几个处理打印的方法传递下来。每个项都有多个数据列。我认为您正在尝试实现属于ViewModel/Controller类的内容。尝试拆分模型/视图模型中的数据,而不是拆分属于UI的数据。@helb
DataGrid
中的数据是动态输入的。例如,一些数据是从数据库加载的;有些是用户通过UI添加的。除了多页打印之外,这些方法现在已经完成。printing类最多可以处理14行。我现在要做的就是递归地运行
Print
方法。我可以将
ItemCollection
放入
ArrayList
,但之后不能返回到
ItemCollection
。有什么想法吗<代码>var DataOverse=新的ArrayList(数据);DataOverse.Removate(0,14)