DBS

.NET~~勇往直前!后来者居上!!

导航

二维数组取最大数

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string dt1 = "2008-10-15 09:09:09";
        string dt2 = "2008-10-10 10:09:09";
        string dt3 = "2008-10-17 09:09:09";
        string dt4 = "2008-10-13 09:09:09";


        string[,] shijian = new string[4, 2] { { dt1, "yiqifa" }, { dt2, "linktech" }, { dt3, "heima" }, { dt4,"chengguo"} };

        int max = 0;
        DateTime dt = Convert.ToDateTime(shijian[0, 0]);
        for (int i = 1; i < shijian.GetLength(0); i++)
        {
            if ( dt > Convert.ToDateTime(shijian[i, 0]))
            {
                continue;
            }
            else
            {
                dt = Convert.ToDateTime(shijian[i, 0]);
                max = i;
            }
        }

        Response.Write(shijian[max, 1].ToString());
    }
}

posted on 2008-11-28 23:22  zhangjpb  阅读(280)  评论(0编辑  收藏  举报