1. Statistical functions

Extension methods must be contained in a public static class. This solution uses the following declaration for its StatisticsExtensions class:

public static class StatisticsExtensions{    ...}

Extension methods must also be declared as public and static. Their first parameter should be marked with the this keyword to indicate that the parameter is the object that is being extended.

The following code shows the TruncatedMean extension method:

// Return the truncated mean of an IEnumerable of numbers.// Set discardNumber to the number of values to discard at the// top and bottom. For example, set discardNumber = 5 to// discard the 5 largest and smallest values.public static double TruncatedMean<T>(this IEnumerable<T> values, ...

Get The Modern C# Challenge 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.