Okay, so I did decide to show you the general idea of what a delegate is.
Okay, we will cover delegates in a lot more detail later on because they are very important when it
comes to events, and that is very important whenever it comes to graphical user interfaces.
So let's have a look at what a delegate is on a super super high level okay.
So in C sharp a delegate is like a pointer or reference to a method.
It allows you to pass methods as arguments to other methods, store them in variables and call them
later.
This is useful when you want your code to be flexible and able to handle different behaviors that aren't
predetermined.
Now the second part like this that aren't predetermined.
That is something that we're going to cover later on.
For now, what I want you to understand is that a lambda expression is nothing other than a very simplified
method.
And this what we have here.
So x becomes x greater ten.
If we want to convert that into a classical method it would look like this.
So I prepared this method.
Public static bool is greater than ten int x return x greater ten.
So how does that make sense.
Well the thing is basically it's the same thing as what we have here.
We can assign a lambda into a predicate which is a delegate.
But what we can do as well is we can assign a full method so we can go ahead and use this is greater
than ten and assign it to our predicate.
So this is greater than ten is actually a method.
Right.
And this method returns a bool.
The predicate requires to get a bool because it returns a bool itself.
Okay.
You see here.
And what's important however, is that we don't call the method.
So we don't use the brackets after that.
We cannot do that.
We can, however, assign the method name directly as the predicate, and the logic is covered in here
inside of our method that we created ourselves.
So now we have simplified.
Let me go back here.
Now instead of having to build this method, what we just did is we just said, okay, the logic is
the same as this lambda expression.
And you can assign a lambda expression into a delegate.
Because a delegate, as I said earlier, is like a pointer or reference to a method.
Okay.
Now what is going on with this find all because we need to understand find all better in order to understand.
This predicate is greater than ten better.
So let's jump into find all.
Because what find all does is it first checks whatever we're passing to it, which is a predicate right
of any type.
So this is generic.
As I said we're going to cover generics later on of any type.
And we're saying if there's no match.
So if match equals null then just throw an error.
But if there is a match now go ahead and create a list and go through every single item in that list
and check if there is a match.
Now what is this match?
Well, the match is basically the logic that we have defined here.
So we have defined when it is a match, and a match is always then when our X is greater than ten.
So under the hood a lot is going on inside of this find all method, which is why it needs a predicate.
So you cannot just enter the variable or the data itself that you want.
You cannot just enter, let's say greater ten.
So it would be a lot easier to just say something like greater ten for example, or ten greater x greater
ten or something like that.
But that's not how it works.
So we need to bring it into the right format where we are using a predicate for it.
So now a lot of keywords came together right?
Lambdas predicates and delegates.
So I summarize it once again a predicate under the hood is a delegate.
A delegate allows us to store a lambda inside of it.
A lambda is just a very simplified method that will not be callable, but can be executed straight away
whenever the predicate is used.
So this find all will take this predicate as the base rule in order to know what it needs to match.
And that's it for this video.
Now, if this went over your head, don't worry about it, okay?
This is something where it's totally fine.
If you at this point, the only thing you understood is that here we're creating a filter and we're
passing on the filter to our find all method to then just find all items that fit that filter.
So if that's all you memorized out of this lecture and understood out of this lecture, you're golden.
Okay.
You don't need to know all of the other stuff of what I explained in the last 1 or 2 videos in depth
already.
I just wanted to make sure that you do know what's going on under the hood, but we're going to cover
those things in a lot more depth later on in the course.