最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#中l(wèi)ist用法實(shí)例

 更新時間:2016年06月27日 15:18:56   作者:smartsmile2012  
這篇文章主要介紹了C#中l(wèi)ist用法,結(jié)合實(shí)例形式分析了C#中l(wèi)ist排序、運(yùn)算、轉(zhuǎn)換等常見操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了C#中l(wèi)ist用法。分享給大家供大家參考,具體如下:

protected void Page_Load(object sender, EventArgs e)
{
  List<string> studentNames = new List<string>();
  studentNames.Add("John");
  studentNames.Add("Mary");
  studentNames.Add("Rose");
  //顯示各元素
  foreach (string item in studentNames)
  {
    Response.Write(item);
    Response.Write("<br/>");
  }
  Response.Write("<br/><br/>");
  //List轉(zhuǎn)換成符號分隔字符串
  string studentAllName = string.Join(",", studentNames.ToArray());
  Response.Write(studentAllName);
  Response.Write("<br/><br/>");
  List<decimal> studentScore = new List<decimal>();
  studentScore.Add(100);
  studentScore.Add(98);
  studentScore.Add(59);
  //排序
  studentScore.Sort();
  //反轉(zhuǎn)排序
  studentScore.Reverse();
  //顯示各元素
  foreach (decimal score in studentScore)
  {
    Response.Write(score);
    Response.Write("<br/>");
  }
  //總計SUM
  Response.Write("總分" + studentScore.Sum());
  Response.Write("<br/>");
  //List中是否存在
  Response.Write(studentScore.Exists(MatchPRE));
  Response.Write("<br/><br/>");
  //List轉(zhuǎn)換成JSon
  List<Student> list = new List<Student>();
  for (int i = 0; i < 5; i++)
  {
    Student a = new Student();
    a.Name = "張三" + i;
    a.Age = i;
    a.Sex = "男";
    list.Add(a);
  }
  string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(list);
  Response.Write(json);
  Response.Write("<br/><br/>");
}
private static bool MatchPRE(decimal p)//條件匹配函數(shù),list1中每個元素都會傳入P中                                      //匹配后函數(shù)返回
{
  if (p == 100)//此句為匹配條件,如果匹配,返回,你可以隨意更改成你想要的值
    return true;
  else
  {
    return false;
  }
}
public struct Student
{
  public string Name;
  public int Age;
  public string Sex;
}

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#程序設(shè)計之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計入門教程

希望本文所述對大家C#程序設(shè)計有所幫助。

相關(guān)文章

最新評論

安远县| 万盛区| 古蔺县| 缙云县| 郁南县| 阿合奇县| 吴桥县| 沙雅县| 枞阳县| 宁夏| 连山| 江城| 馆陶县| 麻栗坡县| 石柱| 保亭| 兴和县| 临汾市| 泰宁县| 宜昌市| 会东县| 清水县| 增城市| 光山县| 准格尔旗| 介休市| 黄山市| 嘉峪关市| 从化市| 乌恰县| 乐亭县| 宁河县| 甘南县| 南丹县| 新干县| 乐东| 裕民县| 茂名市| 黄浦区| 平塘县| 广汉市|