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.
Implement the task array - C# Tutorial
From the course: C# Hands-on Practice with Data-Structures
Implement the task array
Let's implement a task array to keep track of our tasks in a to-do list application. In this app, we're representing each task as a TodoItem, each with its own ID and description. This will be used in the TodoService class. The Service class will manage our tasks and expose methods to interact with them. We can use the array data structure to store our TodoItem objects. We'll also create a count variable that will act as an index for keeping track of the number of tasks. When we add a task, we'll add the task to our array at the count index. Then we'll increment the count. We'll also set the TodoItem's ID to the value of the count. This ensures that each ID is unique. In fact, we'll use this ID to determine which item to remove if the Delete method is used. Let's implement Delete. To remove an item, we'll need to iterate through the tasks and find the item with the passed-in ID. When we do find the item we want to delete, we'll need to shift the existing items to the left to fill the…