public Statistic Average(String category, int precision, params Statistic[] stats) { int paramsCount = stats.Count <Statistic>(); // Populate param list for main data StatisticsData[] mainStats = new StatisticsData[paramsCount]; for (int i = 0; i < paramsCount; i++) { mainStats[i] = stats[i].MainData; } // Compute average for main data StatisticsData mainDataAverage = MainData.Average(MainData.Name, precision, mainStats); // Assume the sub statistics are ordered and are of the same size of the other sub statistics List <StatisticsData> subDataAverages = new List <StatisticsData>(); for (int i = 0; i < SubData.Count; i++) { // Populate a param list with the values for each sub value StatisticsData[] subStats = new StatisticsData[paramsCount]; for (int j = 0; j < paramsCount; j++) { Trace.Assert(SubData.Count == stats[j].SubData.Count, "Trying to compute the average of sub statistics values when their sizes are different."); subStats[j] = stats[j].SubData[i]; } subDataAverages.Add(SubData[i].Average(SubData[i].Name, precision, subStats)); } return(new Statistic(mainDataAverage, category, subDataAverages)); }