首页 > 其他 > 详细

List<T>集合的一些实例

时间:2015-09-25 12:56:24      阅读:273      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web;
using System.Web.Script.Serialization;//转换成json格式需要使用
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{
    public partial class WebForm13 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //List集合额进行排序
            List<string> list = new List<string>();
            list.Add("John");
            list.Add("Mary");
            list.Add("Rose");
            foreach (string item in list)
            {
                Response.Write(item);
            }

            string studentAllName = string.Join(",",list.ToArray());
            Response.Write(studentAllName);

            //List集合进行排序
            List<decimal> studentScore = new List<decimal>();
            studentScore.Add(100);
            studentScore.Add(190);
            studentScore.Add(80);
            //排序
            studentScore.Sort();
            //反转排序
            studentScore.Reverse();
            foreach (decimal item in studentScore)
            {
                Response.Write(item);
                Response.Write("<br />");
            }

            //总计sum
            Response.Write("总分:" + studentScore.Sum());
            Response.Write("<br />");
            //list中是否存在
            //Response.Write(studentScore.Contains(100));
            Response.Write(studentScore.Exists(MatchPRE));

            //List集合转换成json

            List<BLL.Student> Student = new List<BLL.Student>();
            for (int i = 0; i < 5; i++)
            {
                BLL.Student a = new BLL.Student();
                a.Name = "张三" + i;
                a.Age = i;
                a.Sex = "";
                Student.Add(a);
            }
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string json = jss.Serialize(Student);
            Response.Write(json);
            Response.Write("<br/><br/>");
        }

        public static bool MatchPRE(decimal p) 
        {
            if (p == 100)
            {
                return true;
            }
            else 
            {
                return false;
            }
        }

    }
}

 

List<T>集合的一些实例

原文:http://www.cnblogs.com/dongqian/p/4837734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!