[英]How to create an array from a collection
A collection is passed to the function parameters.一个集合被传递给 function 参数。 I need to take an element in the middle from it.
我需要从中取一个元素。 How can i do this?
我怎样才能做到这一点?
private PaperProduct midEl(ICollection<Type> Coll)
{
int index = (Coll.Count() / 2)+1;
Type T = Coll.GetType();
Coll.CopyTo(T[], 10);
}
You can just convert the collection to an array and take the index.您可以将集合转换为数组并获取索引。
var middle = Coll.ToArray()[index];
Or more simple and without conversion:或更简单且无需转换:
var middle = Coll.ElementAt(index);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.