Copy part of a queue to another queue,or even copy from a queue to an array RRS feed

  • Question

  • I am attempting to copy part of a queue to another queue.  As a compromise I tried online a way to copy part of a queue to an array.  

               var values = stocks.Select(s => new DateClose() { Date = s.Date.Date, Close = s.Close });
                var movingAverageQueueAll = new Queue<DateClose>(values);
                  // take part of the movingAverageQueueAll put in an array
                var movingAverageArray = new DateClose[movingAverageQueueAll.Count() - 210].Select(h                 => new DateClose()).ToArray();
                 movingAverageQueueAll.CopyTo(movingAverageArray, 210);

    The issue is on line "movingAverageQueueAll.CopyTo(movingAverageArray, 210);"

    There is not an error but the webpage for the Controller has an internal server error and does not display the data I expect.

    Friday, November 16, 2018 9:58 PM

All replies

  • I found a way to convert the part of a queue to a new array.

     var movingAverageArray = movingAverageQueueAll.Skip(210).Take(movingAverageQueueAll.Count() - 210);

    Saturday, November 17, 2018 11:31 AM
  • Hi DoctorWhoKnew,

    I am glad to know that resolve the issue and share the solution to us, please mark it as answer, it will be beneficial other communities who have the similar issue.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, November 19, 2018 1:06 AM