If you already have the function body you just have to take it out of the main() and put it above or below it. You declare it like this

public double function_name()
{
// Put your method here
}

About this method:

Public : accessibility of the method can be public, private, protected
Double : return type of the function. Since it's an average i would assume it will be a double to capture the decimals
Function_name : you can call your function anything you want. Usually you would use a meaningful name to make it understandable. Put a comment on your function as well if it's complicated so other programmer know about the specifics of the function

Then on your main method you will call the function like this

function_name();

If you are trying to output the average temperature it will look like this

Explanation above is the basics on how to declare and function and how to use it.

To accomplish what you need to do : find lowest, highest and average. You could write 3 different methods to get the values

Public double GetLowestValue();
Public double GetHighestValue();
Public double GetAverageValue();

Pros: you have a method that have one specific job. Easy to maintain

cons: you will have to call it separately. You will be iterating through the list of numbers 3 separate times.

However, you can find a way to be more efficient by reading all the values and storing them into a list and you are just referencing it on your methods.

Public double GetLowestValue( ObservableCollection<double> list)
{
// Start with a really high value
var lowestValue = 9999999999;
// Iterate though the list of values
ForEach(var d in list)
{
// Compare the current value(d is a reference to a value in the list
If(d < lowestValue)
{
// If the value d is less than the variable lowestValue, then change the value to d
lowestValue = d;
}
}
return lowestValue;
}

More efficient : add lines to get all the values you needed. Compare d to a variable containing the Highest value. As well as a variable to accumulate all values to calculate the average

AverageValue = accumulatedValue/ list.Count;

You will need to declare a global variable to store the values that you found. Or you can add a reference to them on the method parameters.

Many conceptual questions have already been asked and answered. Read our FAQ page and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.