I have defined the following:
public ICollection- Items { get; set; }
When I run this code:
Items = _item.Get(\"
Pending more information on the question:
please provide more information on the type of item and the signature of Get
Two things you can try are:
Please note the second will incur a performance hit for the array copy. If the signature (return type) of Get is not an ICollection then the first will not work, if it is not IEnumerable then the second will not work.
Following your clarification to question and in comments, I would personally declare the returning type of _item.Get("001") to ICollection. This means you won't have to do any casting or conversion (via ToList / ToArray) which would involve an unnecessary create/copy operation.
// Leave this the same
public ICollection- Items { get; set; }
// Change function signature here:
// As you mention Item uses the same underlying type, just return an ICollection
public ICollection- Get(string value);
// Ideally here you want to call .Count on the collectoin, not .Count() on
// IEnumerable, as this will result in a new Enumerator being created
// per loop iteration
for (var index = 0; index < Items.Count(); index++)
Best regards,