我是c#noob,但我真的需要专业人士的帮助。我为一个项目使用visual studio 2005,所以我没有math.linq我需要计算一个通用的对象列表的标准偏差。该列表只包含浮点数的列表,没有太复杂的。不过,我从来没有这样做过,所以我需要有人向我展示计算通用列表的标准偏差之前。这里是我的代码,我试图启动上:计算一个通用物体列表的标准偏差
//this is my list of objects inside. The valve data just contains a bunch of floats.
public class ValveDataResults
{
private List<ValveData> m_ValveResults;
public void AddValveData(ValveData valve)
{
m_ValveResults.Add(valve);
}
//this is the function where the standard deviation needs to be calculated:
public float LatchTimeStdev()
{
//below this is a working example of how to get an average or mean
//of same list and same "LatchTime" that needs to be calculated here as well.
}
//function to calculate average of latch time, can be copied for above st dev.
public float LatchTimeMean()
{
float returnValue = 0;
foreach (ValveData value in m_ValveResults)
{
returnValue += value.LatchTime;
}
returnValue = (returnValue/m_ValveResults.Count) * 0.02f;
return returnValue;
}
}
的“锁定时间”是指插入m_ValveResults列表中的“ValveData”对象的浮动对象。
就是这样。任何帮助将不胜感激。由于
欢迎#1。你有一个很好的问题,但为了将来的参考,“PLZ HELP !! ?? @ 11”不是一个好问题标题。 – 2010-06-30 14:25:26
为什么你会接受[这个答案](http://stackoverflow.com/questions/3141692/c-standard-deviation-of-generic-list/3141731#3141731),然后再问同样的问题? – 2010-06-30 14:32:13
@John - 我注意到在这个问题中他指定他使用的是VS 2005,所以他不能使用Linq。 – Greg 2010-06-30 14:36:19