【问题标题】:Using .Net's StatisticFormula Library使用 .Net 的 StatisticFormula 库
【发布时间】:2012-07-12 19:19:15
【问题描述】:

C# 命名空间 System.Windows.Forms.DataVisualization.Charting.StatisticFormula 似乎有一些我需要的统计函数。命名空间记录在MSDN here。我真的很想使用 InverseNormalDistribution(double Z) 函数。问题是构造函数是内部的,所以无论如何我都无法访问我知道的函数。

有什么方法可以访问这个命名空间中的静态函数,还是我必须找到其他解决方案?

【问题讨论】:

  • 你能举一个例子来说明你迄今为止在 C# 代码方面的内容吗?我认为,一旦我们可以看到您正在使用什么以及您如何尝试实现该方法,这将更有意义
  • 我在尝试这个: var stat = new System.Windows.Forms.DataVisualization.Charting.StatisticFormula(); Console.WriteLine(stat.InverseNormalDistribution(0.5)); //它会给我一个编译器错误。

标签: c# .net normal-distribution


【解决方案1】:

您可能可以使用反射,应该这样做:

var statisticFormula = 
    (StatisticFormula) typeof(StatisticFormula).GetConstructor(
        BindingFlags.NonPublic | BindingFlags.Instance,
        null, Type.EmptyTypes, null).Invoke(null);

但这可能是更好的方法:

var chart = new Chart();
var value = chart.DataManipulator.Statistics.InverseNormalDistribution(.15)

【讨论】:

  • 这正是我所需要的(第二部分)。谢谢。
  • 可能想在图表中添加一个 using,即 using (var chart = new Chart()) { return chart.DataM.....; }。有趣的是,如此有用、可重用的代码是如何隐藏在如此繁琐的命名空间和 API 中的。
  • 反射不起作用,因为StatisticFormula 似乎没有非公共构造函数。即使有,我也怀疑它会起作用,因为我在第一次调用其中一个统计方法时尝试使用StatisticFormula F = new DataManipulator().Statistics; 进行尝试失败,出现 NULL 指针异常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多