The Terminate method returns the result of aggregation calculated over every group. Let's dive right into its definition, shown in the following code sample:
//declaration generated by Visual Studiopublic SqlString Terminate ()//complete code with changed declaration of the methodpublic SqlDouble Terminate (){ double valueCount = (double)values.Count; //calculating mean double sum = 0; foreach (var item in values) //sum of values in the list { sum += item; } double mean = sum / valueCount; //mean of values in the list //powered differences double poweredDiffsFromMean = 0; foreach (var item in values) //the difference between value and the mean { poweredDiffsFromMean += Math.Pow((item - mean), this.n);