And this video, we are going to get the maximum temperature out of our array.
So this is a very important thing to learn.
You need to know how to get the max value as well as the min value inside of an array.
And there is a very simple trick for that.
So what you can do is you can just take your variable so your array in this case temperature dot.
And you can see that there is the min as well as max.
So this max method will return the maximum value in a sequence of int values which temperature is.
So if you want to have the max value you can just go ahead and get it like this.
So now we can use this here to write that onto the screen as well.
So here I'm just going to say the max temp was.
And then within my curly brackets I just do the temperature dot max calculation.
So now I can do the same thing for the min temp.
So min temp was.
And here I'm using the min method this one here.
So this now gives me the maximum temperature as well as the minimum temperature that we have inside
of our randomized weather simulator.
So let me run that and enter the number of days let's say ten days.
So the average is 23.6.
And the max temperature was 37 and the min temperature was seven.
So that's pretty much it.
That's how you can get the min and max value.
However, I want to show you how you can get it by using your own method.
Okay.
So this is a very nice little feature that is available in C sharp.
But what if you actually need to calculate the mean temperature yourself or get it yourself.
So what you can do is you can use this here.
So min temperature where you pass in the array of temperature.
And this one will be an array here an int array of temp.
And now what will happen in here is where you create a value.
That is the minimum value.
And the minimum value however will start with the first entry inside of your temperature array.
So if you look at the array let's say you have ten values in there.
And if you don't know which one is the lowest, you just assume that the first one is the lowest, and
then you compare it with the second entry.
And if the second entry is lower than the first, you just say, okay, the second entry is the lowest,
and then you do that for every single value inside of your array.
And once you've done that, you will know which one is the lowest value, because you only store the
lowest value inside of this variable called min.
So how does that work in an array.
So I can just say for each int I in temperature.
Now you could call this one temp in temperature.
That would be fine as well.
So here I'm going to say if temp is less than min then min is equal to temp.
And here that's pretty much it.
Yeah.
So with this way we will also get the minimum value.
And now we just need to return min.
And that's how we can get the minimum temperature ourself.
So technically this is the same thing.
So what we have inside here is pretty much the same thing.
Only that obviously we don't need to create an extra method for that.
I just wanted to show you how such a method would look like.
So this is what min temperature would do.
And now let's compare the two with each other.
So let's take this line here.
And instead of using temperature dot min we are going to use our method that we called min temperature
okay.
Min temperature we're going to call it like so.
And we're going to pass in the temperature int.
So like so.
And now let's run it again and see if it compares.
So we see min temp was minus eight.
Min temp was minus eight.
So it seems like our own method that we created does the trick.
So it works exactly the same way as this really cool min method that is available for arrays which have
integers in them.
So this min method should also work for doubles and other simple number data types, so to speak.
But yeah, that's pretty much how you can see how the internals of it work.
And I'd say we have one more step ahead of us, and that is to find out what the most common condition
is.
Okay, that will be a little more complicated, but let's do that in the next video.