A collection is passed to the function parameters. 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);
}
CodePudding user response:
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);