C#中l(wèi)ist用法實(shí)例
本文實(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)換成符號(hào)分隔字符串 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/>"); } //總計(jì)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中每個(gè)元素都會(huì)傳入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è)計(jì)之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#常見(jiàn)控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#將Excel中的數(shù)據(jù)轉(zhuǎn)換成DataSet
這篇文章主要介紹了C#將Excel中的數(shù)據(jù)轉(zhuǎn)換成DataSet的方法,非常簡(jiǎn)單實(shí)用,從本人項(xiàng)目中提取出來(lái)的,推薦給大家,希望對(duì)大家學(xué)習(xí)C#能夠有所幫助。2015-03-03C#通過(guò)yield實(shí)現(xiàn)數(shù)組全排列的方法
這篇文章主要介紹了C#通過(guò)yield實(shí)現(xiàn)數(shù)組全排列的方法,以實(shí)例形式較為詳細(xì)的分析了全排列的概念及C#的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03c#基于WinForm的Socket實(shí)現(xiàn)簡(jiǎn)單的聊天室 IM
這篇文章主要介紹了c#基于WinForm的Socket實(shí)現(xiàn)簡(jiǎn)單的聊天室 IM的步驟,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-05-05使用c#實(shí)現(xiàn)隨機(jī)數(shù)猜數(shù)游戲的示例代碼
這篇文章主要介紹了使用c#實(shí)現(xiàn)隨機(jī)數(shù)猜數(shù)游戲的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09C# ODP.NET 調(diào)用Oracle函數(shù)返回值時(shí)報(bào)錯(cuò)的一個(gè)解決方案
這篇文章主要介紹了C# ODP.NET 調(diào)用Oracle函數(shù)返回值時(shí)報(bào)錯(cuò)的一個(gè)解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12C#簡(jiǎn)單實(shí)現(xiàn)在網(wǎng)頁(yè)上發(fā)郵件的案例
本文分享一個(gè)C#利用SMTP發(fā)送郵件的案例,提供了前后臺(tái)代碼,方便大家學(xué)習(xí)。2016-03-03