c#用for循环得出的几个数,求最大值。

c#用for循环得出的几个数,求最大值。


distanceLongLat得出来的是多个值,怎么从中选出最大值呢???

SqlDataReader sdr = SqlHelp.Reader("select * from 苏州科技学院$");
            DataTable table = new DataTable();
            table.Load(sdr);
            double x, y;
            string result = "";
            //string x = "";
            for (int i = 0; i < table .Rows.Count ; i++)//遍历每一行
            {
                for (int j = 0; j < table .Columns.Count ; j++)//遍历列
                {
                    //result += table.Rows[i][j].ToString(); //逐行逐列显示每个单元格的数值。
                    x = Convert.ToDouble(table.Rows[i][0]);
                    //x = table.Rows[i][0].ToString ();
                    y = Convert.ToDouble(table .Rows [i][1]);

                    double Lx=maxLatitude-x;
                    double Ly = y - minLongitude;

                    double distanceLongLat=Math.Sqrt(Lx*Lx +Ly *Ly);
                    //MessageBox.Show(distanceLongLat+"");
                }
                //result += Environment.NewLine; //一行遍历完成就写入回车。
                //x += Environment.NewLine; //一行遍历完成就写入回车。
            }
SqlDataReader sdr = SqlHelp.Reader("select * from 苏州科技学院$");
            DataTable table = new DataTable();
                        List<double> list = new List<double>();
            table.Load(sdr);
            double x, y;
            string result = "";
            //string x = "";
            for (int i = 0; i < table .Rows.Count ; i++)//遍历每一行
            {
                for (int j = 0; j < table .Columns.Count ; j++)//遍历列
                {
                    //result += table.Rows[i][j].ToString(); //逐行逐列显示每个单元格的数值。
                    x = Convert.ToDouble(table.Rows[i][0]);
                    //x = table.Rows[i][0].ToString ();
                    y = Convert.ToDouble(table .Rows [i][1]);

                    double Lx=maxLatitude-x;
                    double Ly = y - minLongitude;

                    double distanceLongLat=Math.Sqrt(Lx*Lx +Ly *Ly);
                                        list.Add(distanceLongLat);
                    //MessageBox.Show(distanceLongLat+"");
                }
                                MessageBox.Show(list.Max().ToString());
                //result += Environment.NewLine; //一行遍历完成就写入回车。
                //x += Environment.NewLine; //一行遍历完成就写入回车。
            }