Hello there and welcome.
See sharp list what is a list in C sharp.
A list is an object which holds variables in a specific order lists are like arrays.
But one main difference between a list and an array is that with a list they are dynamically sized.
That means you don't necessarily have to know what is going to be in the list so you can not die dynamically
added on or their size as it goes on.
While an array has a fixed size.
So if you want to use an array you know beforehand what the array will contain.
But if you're not sure what the amount of variables will be is best to use a list because a dynamically
sized.
The basic syntax for right in the list is this.
So you start with a name list followed by the data type.
In this example here we are defining a list called numbers which will hold integers integers are numbers
once the list has been initialized we can insert numbers into the list.
I have got visual studio opened and I've just commented out some call I wrote in in the lecture for
a raise.
I'm just going to use the same the same program here to keep an example of how to set up a list.
So we're going to start by initializing the list to type in list followed by the data type which would
be an integer
followed by the name.
I want to keep the list I in numbers and to create a new instance of it.
You do the equals to new list and path in the data type and then a semicolon at the end.
So
before the semicolon you need to put parentheses open on closing period.
This is OK.
So now that the list has been initialized I can append or add to the list to add to the list.
All I need is the name of the list which is numbers
followed followed by a dot and then the word add add is a method a built in method and a parent who
sees are passing the number I want to add Okay so I've now added.
And number one I can do the same.
Just copy it a few times just to save time and come here again.
Now just change the numbers or this change to 2.
These are changed to 3 and these are changed to 4
so we can display the count of the of what's in the list.
Using a console log so we can display it on the console so you typing console
console dot right line and in the right line you pass in the name of the list.
Numbers don't count.
So we use the count to count the count as a built in function.
So we need to use the count to count the numbers in the list and we're going to attach a console the
read line to that as well.
Because if we don't use a console the red line we will not see see displayed on the screen long enough
without using the console.
The red line.
It will just execute quickly and exit the screen.
But with you if you are the console the red line it executes and displays the result on the screen.
So we know we've got four items in the list.
So I expect the count to show four.
So click on Start to debug it.
As you can see it is showing for.
So the same way you add to a list.
You can also remove from a list.
So if I wanted to remove from the list all I had to do was just come down here.
I type here.
I'll start with the name of the variable with which is the the list name list names called numbers.
So I type in numbers
dot remove.
Notice the removed method here.
And then in that are passing the value I want to remove.
So I want to remove for
okay.
If I now execute this statement I expect the list to only display a count of three.
So let me run that so that we can see as you can see is displayed a count of three.
So we've done an example using an integer.
So I'm gonna do an example now using a string is basically the same thing you just substitute the integer
with a string.
So you just I'm just gonna.
Quickly to save time and then I'll explain it to you but it's basically the same.
Okay so I defined another list here this time a string.
So we've already have already showed you an example with an integer.
So this is an example with a string.
I've created a list the data type is a string I've given it the name of fruits created a new instance
here called list and use the add method here to add to the list.
So I've added this for items to the list and I've got to console the right line here with a count.
So this count will enable me to count what we have in the list to is should display for items.
So let me run that click on Start and it should display form so she can see they've got four displayed.
All right.
So you can experiment and try and create various list your self notice that with the string data type
you have to enclose the values in quotes because they ha text does you know where B computer can understand
them.
So that's set for this lecture on list.
Thanks for watching.
Bye for now.