加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

获取ArrayList集合中的最大值、最小值

(2013-11-01 12:34:55)
标签:

it

分类: C#

获取ArrayList集合中的最大值、最小值

 

//获取最大值

public double CalculationMax(ArrayList sampleList)
 {
            try
            {
                double maxDevation = 0.0;
                int totalCount = sampleList.Count;
                if (totalCount >= 1)
                {
                    double max = Double.Parse(sampleList[0].ToString());
                    for (int i = 0; i < totalCount; i++)
                    {
                        double temp = Double.Parse(sampleList[i].ToString());
                        if (temp > max)
                        {
                            max = temp;
                        }
                    } maxDevation = max;
                }
                return maxDevation;
            }
            catch (Exception ex)
            {
                LogInfo.InsertErrorSystemLog("通用计算公式", "获取集合中的最大值:"   ex.Message);
                throw ex;
            }

  }

 

//获取最小值

public double CalculationMin(ArrayList sampleList)
 {
            try
            {
                double mixDevation = 0.0;
                int totalCount = sampleList.Count;
                if (totalCount >= 1)
                {
                        double min = Double.Parse(sampleList[0].ToString());
                        for (int i = 0; i < totalCount; i++)
                        {
                            double temp = Double.Parse(sampleList[i].ToString());
                            if (min > temp)
                            {
                                min = temp;
                            }
                        } mixDevation = min;
                }
                return mixDevation;
            }
            catch (Exception ex)
            {
                LogInfo.InsertErrorSystemLog("通用计算公式", "获取集合中的最小值:" + ex.Message);
                throw ex;
            }
        }

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有