2

I have a list of about 1000 items and I want to debug and examine in the watch window only items in the range 500 to 550. Is this possible in C# in Visual Studio?

I tried items[500..550] but I got an error

Predefined type 'System.Range' is not defined or imported

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tim Gradwell
  • 2,312
  • 5
  • 24
  • 25
  • Does `myCollection.Skip(500).Take(50)` work? (with `using System.Linq;` in the context) – Flydog57 Oct 26 '21 at 00:19
  • Parital credit :-) It does give me just those items, but now they're numbered 0 to 50. I could still do with seeing the original indexes if at all possible. (If I don't get an answer with the indexes I'm looking for in the next day or so, give me yours as an answer and I'll mark it as the correct answer thanks) – Tim Gradwell Oct 26 '21 at 00:25
  • Not used Linq for a while but perhaps you could zip Flydog57's answer with a range (500,500+50)? – David Waterworth Oct 26 '21 at 04:07
  • You could format your own display; `.Select( (obj, index) => $"{index} - {obj}").Skip(500).Take(50)` – Jeremy Lakeman Oct 26 '21 at 04:28
  • Unfortunately `items.Skip(500).Take(50).Zip(Enumerable.Range(500, 550), (first, second) => first + " " + second)` just gives me a collection of strings. I need to be able to drill into the items. – Tim Gradwell Oct 26 '21 at 22:49

0 Answers0