Welcome back.
In this demo, we are going to start with Link and therefore let's go ahead and create a new console
app and I'm going to call it Link one.
Once that is created, let's go ahead and create one simple array of integers, and I'm going to call
that numbers.
This is going to be new int and I'm going to add some values in here already.
So one, two, three, four, five and so forth, up to nine.
So this is my little array called numbers and plural numbers.
And now what I want to do is I want to get all the odd numbers out and there are multiple ways to do
that.
And we have seen, for example, modulo four that we could use modulo and see everything that goes well
that can be divided by two and has a remainder.
That would be an odd number.
Right.
But there is a, let's say, more sophisticated way.
So we can go ahead and create a new method.
And I'm going to use a static void method that are called odd numbers and it needs an array of integers.
So it's going to be numbers.
I'm just going to call this parameter numbers.
Now in here, I'm going to simply write into the console first.
I'm going to say something like odd numbers.
So it will print out all the odd numbers.
Now, in order to get the odd numbers, I will use something called an I enumerable.
As you can see, there is an AI enumerable, there is an AI enumerator.
They are slightly different and the one that we want to use is an I enumerable, which is a collection.
So it's similar to a list, but it has some additional functionality.
So I'm going to use the I enumerable of integers.
So it should be of type integers.
Well, our numbers is of type int.
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
one odd numbers.
This list of type integer, which is an enumerable should contain odd numbers.
And in order to get them or fill them with odd numbers, I'm going to use link.
So I'm going to use an expression like that from number in numbers, which looks similar to a for each
statement which we have seen already.
But now I'm going to say where number modulo two not equals zero select number.
So that's it.
That's our link statement.
So checks for every single number that we have in numbers if it's divisible by two and has no remainder
and if it does have a remainder, then we want to add that to our list.
So we want to add that to our odd numbers list.
So it's very similar to SQL, which we have seen.
Right.
But it's not SQL, it's Lync.
And the cool thing is it uses a very basic array.
It doesn't need to use a database or it doesn't need to use XML or anything like that.
It simply uses this very, very basic array that we have created here.
So this from number in numbers is basically a for each loop.
Then where is a filtering operator?
What we do is simply filter out ints by all odds.
So this is what this statement here does and then select is a projection operator.
What it basically does here is it decides what will be written in odd numbers and whatnot.
And that's it.
So that's our whole line and it's pretty cool.
So now we can go ahead and print that onto the console, so see W and print out the odd numbers.
And now what we also can do is for each int i n or numbers print it out equally so individually.
C w i.
All right.
As you can see, you can use for each on an eye enumerable, which is pretty cool as well.
So it's very similar to an array or to a list, but it has some additional advantages and we will see
some of them.
So let's call our numbers here, our numbers and we're going to hand over numbers and now we can use
console dot read key in order to see something on the console.
So let's run it.
And we can see all the numbers.
And as you see here, what I've written here console right line of numbers is a system link dot enumerable
where array iterator.
And what it then says is one, three, five, seven and nine.
So it gave us all of the odd numbers from our numbers array and now we could, instead of using an array,
we could use a complete data table or we could use XML data in order to check it out.
So that's a cool thing about using link and you will see a lot more about Link and what it does in the
next video.
So see you there.