C# Collection and Iteration
C# has powerful structures for dealing with collections and other data structures. In this blog, we'll be using string formatting and lists . Click on the links if you haven't done them in C# before. var names = new List<string> { "nobita", "bheem", "oggy", "oggy cockroach", "ninja" }; foreach (var name in names) { if(name.StartsWith("oggy")) { Console.WriteLine($"Need to remove {name}!"); names.Remove(name); } } This code tries to remove names starting with "oggy" from a list. Try it in the interactive editor offered by the above tutorial (click 'Enter focus mode' at the bottom of this site ) Does it work? No! Which is the line that's causing the crash? How would you resolve it? Click here to power back