1
00:00:00,630 --> 00:00:02,350
Hello there and welcome.

2
00:00:02,380 --> 00:00:07,340
See sharp list what is a list in C sharp.

3
00:00:07,440 --> 00:00:18,930
A list is an object which holds variables in a specific order lists are like arrays.

4
00:00:18,930 --> 00:00:30,820
But one main difference between a list and an array is that with a list they are dynamically sized.

5
00:00:30,890 --> 00:00:40,010
That means you don't necessarily have to know what is going to be in the list so you can not die dynamically

6
00:00:40,340 --> 00:00:43,870
added on or their size as it goes on.

7
00:00:44,690 --> 00:00:48,330
While an array has a fixed size.

8
00:00:48,350 --> 00:00:55,840
So if you want to use an array you know beforehand what the array will contain.

9
00:00:55,920 --> 00:01:05,270
But if you're not sure what the amount of variables will be is best to use a list because a dynamically

10
00:01:05,600 --> 00:01:07,580
sized.

11
00:01:08,210 --> 00:01:12,950
The basic syntax for right in the list is this.

12
00:01:13,040 --> 00:01:17,750
So you start with a name list followed by the data type.

13
00:01:17,870 --> 00:01:29,090
In this example here we are defining a list called numbers which will hold integers integers are numbers

14
00:01:31,260 --> 00:01:39,440
once the list has been initialized we can insert numbers into the list.

15
00:01:39,790 --> 00:01:48,890
I have got visual studio opened and I've just commented out some call I wrote in in the lecture for

16
00:01:48,960 --> 00:01:49,650
a raise.

17
00:01:49,650 --> 00:02:01,410
I'm just going to use the same the same program here to keep an example of how to set up a list.

18
00:02:01,530 --> 00:02:12,150
So we're going to start by initializing the list to type in list followed by the data type which would

19
00:02:12,150 --> 00:02:13,170
be an integer

20
00:02:15,840 --> 00:02:17,630
followed by the name.

21
00:02:17,660 --> 00:02:24,920
I want to keep the list I in numbers and to create a new instance of it.

22
00:02:25,150 --> 00:02:41,380
You do the equals to new list and path in the data type and then a semicolon at the end.

23
00:02:41,840 --> 00:02:42,350
So

24
00:02:44,930 --> 00:02:51,080
before the semicolon you need to put parentheses open on closing period.

25
00:02:51,090 --> 00:02:52,110
This is OK.

26
00:02:53,720 --> 00:03:02,890
So now that the list has been initialized I can append or add to the list to add to the list.

27
00:03:02,900 --> 00:03:06,620
All I need is the name of the list which is numbers

28
00:03:10,130 --> 00:03:21,180
followed followed by a dot and then the word add add is a method a built in method and a parent who

29
00:03:21,200 --> 00:03:28,810
sees are passing the number I want to add Okay so I've now added.

30
00:03:28,980 --> 00:03:32,600
And number one I can do the same.

31
00:03:32,820 --> 00:03:40,800
Just copy it a few times just to save time and come here again.

32
00:03:44,650 --> 00:03:49,720
Now just change the numbers or this change to 2.

33
00:03:50,280 --> 00:03:57,380
These are changed to 3 and these are changed to 4

34
00:04:01,620 --> 00:04:08,800
so we can display the count of the of what's in the list.

35
00:04:08,970 --> 00:04:13,530
Using a console log so we can display it on the console so you typing console

36
00:04:17,060 --> 00:04:31,790
console dot right line and in the right line you pass in the name of the list.

37
00:04:32,690 --> 00:04:35,240
Numbers don't count.

38
00:04:35,800 --> 00:04:43,680
So we use the count to count the count as a built in function.

39
00:04:43,690 --> 00:04:54,200
So we need to use the count to count the numbers in the list and we're going to attach a console the

40
00:04:54,220 --> 00:04:56,380
read line to that as well.

41
00:04:56,680 --> 00:05:04,960
Because if we don't use a console the red line we will not see see displayed on the screen long enough

42
00:05:08,760 --> 00:05:10,250
without using the console.

43
00:05:10,250 --> 00:05:11,580
The red line.

44
00:05:11,580 --> 00:05:15,210
It will just execute quickly and exit the screen.

45
00:05:15,210 --> 00:05:23,220
But with you if you are the console the red line it executes and displays the result on the screen.

46
00:05:23,220 --> 00:05:26,610
So we know we've got four items in the list.

47
00:05:26,640 --> 00:05:29,130
So I expect the count to show four.

48
00:05:29,610 --> 00:05:34,270
So click on Start to debug it.

49
00:05:35,310 --> 00:05:38,950
As you can see it is showing for.

50
00:05:39,030 --> 00:05:45,030
So the same way you add to a list.

51
00:05:45,090 --> 00:05:49,380
You can also remove from a list.

52
00:05:49,380 --> 00:05:57,420
So if I wanted to remove from the list all I had to do was just come down here.

53
00:05:57,420 --> 00:05:58,140
I type here.

54
00:05:58,170 --> 00:06:06,210
I'll start with the name of the variable with which is the the list name list names called numbers.

55
00:06:06,210 --> 00:06:07,830
So I type in numbers

56
00:06:10,110 --> 00:06:12,870
dot remove.

57
00:06:12,870 --> 00:06:15,110
Notice the removed method here.

58
00:06:15,540 --> 00:06:20,130
And then in that are passing the value I want to remove.

59
00:06:20,140 --> 00:06:22,410
So I want to remove for

60
00:06:25,380 --> 00:06:26,580
okay.

61
00:06:26,810 --> 00:06:36,680
If I now execute this statement I expect the list to only display a count of three.

62
00:06:36,680 --> 00:06:43,790
So let me run that so that we can see as you can see is displayed a count of three.

63
00:06:46,100 --> 00:06:49,250
So we've done an example using an integer.

64
00:06:49,640 --> 00:06:58,520
So I'm gonna do an example now using a string is basically the same thing you just substitute the integer

65
00:06:58,880 --> 00:07:00,350
with a string.

66
00:07:00,470 --> 00:07:02,820
So you just I'm just gonna.

67
00:07:02,950 --> 00:07:07,120
Quickly to save time and then I'll explain it to you but it's basically the same.

68
00:07:08,380 --> 00:07:13,980
Okay so I defined another list here this time a string.

69
00:07:14,120 --> 00:07:18,310
So we've already have already showed you an example with an integer.

70
00:07:18,350 --> 00:07:20,970
So this is an example with a string.

71
00:07:21,300 --> 00:07:27,830
I've created a list the data type is a string I've given it the name of fruits created a new instance

72
00:07:27,830 --> 00:07:35,740
here called list and use the add method here to add to the list.

73
00:07:35,870 --> 00:07:43,120
So I've added this for items to the list and I've got to console the right line here with a count.

74
00:07:43,520 --> 00:07:50,350
So this count will enable me to count what we have in the list to is should display for items.

75
00:07:50,350 --> 00:07:59,480
So let me run that click on Start and it should display form so she can see they've got four displayed.

76
00:07:59,480 --> 00:08:00,200
All right.

77
00:08:00,200 --> 00:08:08,400
So you can experiment and try and create various list your self notice that with the string data type

78
00:08:08,400 --> 00:08:16,260
you have to enclose the values in quotes because they ha text does you know where B computer can understand

79
00:08:16,260 --> 00:08:17,460
them.

80
00:08:17,820 --> 00:08:20,910
So that's set for this lecture on list.

81
00:08:20,910 --> 00:08:22,080
Thanks for watching.

82
00:08:22,080 --> 00:08:22,680
Bye for now.
