1 00:00:00,360 --> 00:00:01,230 ‫Welcome back. 2 00:00:01,260 --> 00:00:06,630 ‫In this demo, we are going to start with Link and therefore let's go ahead and create a new console 3 00:00:06,630 --> 00:00:08,880 ‫app and I'm going to call it Link one. 4 00:00:10,890 --> 00:00:18,750 ‫Once that is created, let's go ahead and create one simple array of integers, and I'm going to call 5 00:00:18,750 --> 00:00:19,740 ‫that numbers. 6 00:00:20,340 --> 00:00:28,470 ‫This is going to be new int and I'm going to add some values in here already. 7 00:00:28,470 --> 00:00:32,490 ‫So one, two, three, four, five and so forth, up to nine. 8 00:00:32,700 --> 00:00:39,150 ‫So this is my little array called numbers and plural numbers. 9 00:00:39,270 --> 00:00:46,140 ‫And now what I want to do is I want to get all the odd numbers out and there are multiple ways to do 10 00:00:46,140 --> 00:00:46,440 ‫that. 11 00:00:46,440 --> 00:00:53,100 ‫And we have seen, for example, modulo four that we could use modulo and see everything that goes well 12 00:00:53,100 --> 00:00:55,590 ‫that can be divided by two and has a remainder. 13 00:00:55,590 --> 00:00:56,670 ‫That would be an odd number. 14 00:00:56,670 --> 00:00:57,120 ‫Right. 15 00:00:57,120 --> 00:01:00,870 ‫But there is a, let's say, more sophisticated way. 16 00:01:00,870 --> 00:01:04,110 ‫So we can go ahead and create a new method. 17 00:01:04,110 --> 00:01:12,780 ‫And I'm going to use a static void method that are called odd numbers and it needs an array of integers. 18 00:01:12,780 --> 00:01:15,600 ‫So it's going to be numbers. 19 00:01:15,600 --> 00:01:18,270 ‫I'm just going to call this parameter numbers. 20 00:01:18,600 --> 00:01:22,590 ‫Now in here, I'm going to simply write into the console first. 21 00:01:22,590 --> 00:01:25,770 ‫I'm going to say something like odd numbers. 22 00:01:27,180 --> 00:01:29,550 ‫So it will print out all the odd numbers. 23 00:01:29,550 --> 00:01:35,910 ‫Now, in order to get the odd numbers, I will use something called an I enumerable. 24 00:01:36,540 --> 00:01:40,380 ‫As you can see, there is an AI enumerable, there is an AI enumerator. 25 00:01:40,380 --> 00:01:46,500 ‫They are slightly different and the one that we want to use is an I enumerable, which is a collection. 26 00:01:46,500 --> 00:01:51,690 ‫So it's similar to a list, but it has some additional functionality. 27 00:01:51,690 --> 00:01:56,970 ‫So I'm going to use the I enumerable of integers. 28 00:01:57,090 --> 00:01:59,070 ‫So it should be of type integers. 29 00:01:59,070 --> 00:02:01,230 ‫Well, our numbers is of type int. 30 00:02:01,230 --> 00:02:08,520 ‫So I want to use int well a list of ints which is of type I enumerable and now I'm going to call that 31 00:02:08,520 --> 00:02:09,720 ‫one odd numbers. 32 00:02:10,500 --> 00:02:16,620 ‫This list of type integer, which is an enumerable should contain odd numbers. 33 00:02:16,620 --> 00:02:22,020 ‫And in order to get them or fill them with odd numbers, I'm going to use link. 34 00:02:22,140 --> 00:02:31,800 ‫So I'm going to use an expression like that from number in numbers, which looks similar to a for each 35 00:02:32,280 --> 00:02:34,740 ‫statement which we have seen already. 36 00:02:34,800 --> 00:02:46,080 ‫But now I'm going to say where number modulo two not equals zero select number. 37 00:02:47,040 --> 00:02:48,060 ‫So that's it. 38 00:02:48,060 --> 00:02:49,710 ‫That's our link statement. 39 00:02:49,710 --> 00:02:56,190 ‫So checks for every single number that we have in numbers if it's divisible by two and has no remainder 40 00:02:56,190 --> 00:03:02,430 ‫and if it does have a remainder, then we want to add that to our list. 41 00:03:02,430 --> 00:03:05,340 ‫So we want to add that to our odd numbers list. 42 00:03:06,220 --> 00:03:09,520 ‫So it's very similar to SQL, which we have seen. 43 00:03:09,520 --> 00:03:09,940 ‫Right. 44 00:03:09,940 --> 00:03:11,950 ‫But it's not SQL, it's Lync. 45 00:03:11,950 --> 00:03:16,150 ‫And the cool thing is it uses a very basic array. 46 00:03:16,180 --> 00:03:21,160 ‫It doesn't need to use a database or it doesn't need to use XML or anything like that. 47 00:03:21,160 --> 00:03:25,600 ‫It simply uses this very, very basic array that we have created here. 48 00:03:27,250 --> 00:03:32,440 ‫So this from number in numbers is basically a for each loop. 49 00:03:32,890 --> 00:03:36,400 ‫Then where is a filtering operator? 50 00:03:36,940 --> 00:03:40,660 ‫What we do is simply filter out ints by all odds. 51 00:03:40,660 --> 00:03:46,930 ‫So this is what this statement here does and then select is a projection operator. 52 00:03:46,960 --> 00:03:54,010 ‫What it basically does here is it decides what will be written in odd numbers and whatnot. 53 00:03:55,050 --> 00:03:55,790 ‫And that's it. 54 00:03:55,800 --> 00:03:58,650 ‫So that's our whole line and it's pretty cool. 55 00:03:58,650 --> 00:04:05,460 ‫So now we can go ahead and print that onto the console, so see W and print out the odd numbers. 56 00:04:07,050 --> 00:04:20,670 ‫And now what we also can do is for each int i n or numbers print it out equally so individually. 57 00:04:20,700 --> 00:04:22,940 ‫C w i. 58 00:04:25,630 --> 00:04:25,960 ‫All right. 59 00:04:25,960 --> 00:04:30,820 ‫As you can see, you can use for each on an eye enumerable, which is pretty cool as well. 60 00:04:30,820 --> 00:04:38,050 ‫So it's very similar to an array or to a list, but it has some additional advantages and we will see 61 00:04:38,050 --> 00:04:38,710 ‫some of them. 62 00:04:38,710 --> 00:04:47,710 ‫So let's call our numbers here, our numbers and we're going to hand over numbers and now we can use 63 00:04:47,710 --> 00:04:56,830 ‫console dot read key in order to see something on the console. 64 00:04:56,830 --> 00:04:57,700 ‫So let's run it. 65 00:04:58,550 --> 00:05:00,320 ‫And we can see all the numbers. 66 00:05:00,560 --> 00:05:08,180 ‫And as you see here, what I've written here console right line of numbers is a system link dot enumerable 67 00:05:08,180 --> 00:05:10,070 ‫where array iterator. 68 00:05:10,990 --> 00:05:14,770 ‫And what it then says is one, three, five, seven and nine. 69 00:05:14,770 --> 00:05:21,730 ‫So it gave us all of the odd numbers from our numbers array and now we could, instead of using an array, 70 00:05:21,730 --> 00:05:27,280 ‫we could use a complete data table or we could use XML data in order to check it out. 71 00:05:27,280 --> 00:05:33,340 ‫So that's a cool thing about using link and you will see a lot more about Link and what it does in the 72 00:05:33,340 --> 00:05:34,030 ‫next video. 73 00:05:34,030 --> 00:05:35,230 ‫So see you there.