public static class DoubleExtensions {
public static double Sqrt(this double x) {
if (x < 0) throw new ArgumentOutOfRangeException(nameof(x), "負數無實數平方根");
return Math.Sqrt(x);
}
}
// 用法
double d = 16.0;
Console.WriteLine(d.Sqrt()); // 4.0