Implementing the terminate method

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);

Get Hands-On Data Science with SQL Server 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.