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;
}
}
}
}
原文:http://www.cnblogs.com/dongqian/p/4837734.html