From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Add items to a list

Add items to a list

- [Instructor] In this video, we'll look at how to add and insert some items into an existing list. I've already got the code written here and I've got a break point. So what I'm doing is I'm creating a variable called color names, it's a list of strings, and then I'm calling add twice. I'll add two new rows to my list. So I'll step through my code. And as I get through this line of code, you'll see that my color names has a count of two. There's scarlet and there's magenta. Now there's two other ways we can add items. There's the insert method, so I can specify a position and then the value that I want to insert. So I'm putting this at the start of the list. See that added here at position number zero. And there's also the ability to add a range of items. Now, this is the same syntax we looked at earlier when we were initializing a list. I'm doing the same thing here when I call add range. I just pass in the limited list inside a set of curly braces. So let's run this line of code…

Contents