From the course: C# Hands-on Practice with Data-Structures
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Scale an array for increasing task count - C# Tutorial
From the course: C# Hands-on Practice with Data-Structures
Scale an array for increasing task count
For a small to-do list, our application works as expected. We can add a few items, but our array only has enough space for 10 items. We only allocated 10 spots in the array. What happens when we add an 11th? There's our 10th item, and let's try our 11th. It doesn't get added in the UI. Let's take a look at the console output. It looks like we get an index out-of-bounds exception. This happens when we try to access an item in an array at an invalid index. To fix this, we can resize the task array to be larger when it gets too full. Now this error occurs when we try to add an item to an array. So let's modify the Add methods logic. If the count equals the length of the array, we'll want to resize it. Otherwise, we'll continue business as usual and add the item to the array. Let's create that helper method. To resize the array, we'll create a new array that's twice the size of the current array. This should give us a good amount of space for new tasks without taking up an excessive…