首页 / 更多教程 / .net 泛型集合排序,查找
.net 泛型集合排序,查找
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了.net 泛型集合排序,查找,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3148字,纯文字阅读大概需要5分钟。
内容图文
![.net 泛型集合排序,查找](/upload/InfoBanner/zyjiaocheng/1084/a904916ee4f3412683cc0aefe85c62cd.jpg)
using System; using System.Collections.Generic; using System.Web; using System.Web.Services; using System.Web.Script.Serialization; using System.Xml; using System.Collections; using System.Linq; /// <summary> /// WSxml 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] publicclass WSxml : System.Web.Services.WebService { public WSxml () { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] publicstring HelloWorld() { return"Hello World"; } [WebMethod] publicstring saveXml(string cName, string age, string mobile, string email, string ads) { DateTime dt = DateTime.Now; string cdate = dt.ToString(); XmlDocument xmldoc = new XmlDocument(); string xmlFilePath = HttpContext.Current.Server.MapPath("~/data/content.xml"); xmldoc.Load(xmlFilePath); //查找根节点 XmlNode chat = xmldoc.SelectSingleNode("chat"); //使用xpath表达式选择文档中所有的tp子节点 XmlNodeList typeNodeList = xmldoc.SelectNodes("/chat/tp"); string str = string.Empty; //定义一个List泛型集合 List<string> mlist = new List<string>(); if (typeNodeList != null) { string mbl = string.Empty; foreach (XmlNode tpNode in typeNodeList) { //通过Attributes获得属性名字为mobile的属性 mbl = tpNode.Attributes["mobile"].Value; //循环将mobile加入List泛型集合里 mlist.Add(mbl); } } //查找是否存在Listif (mlist.Contains(mobile)) { return"您的手机号码已被注册,请勿重复注册"; } //创建节点 XmlElement infor = xmldoc.CreateElement("tp"); infor.SetAttribute("cName", cName); infor.SetAttribute("age", age); infor.SetAttribute("mobile", mobile); infor.SetAttribute("email", email); infor.SetAttribute("ads", ads); infor.SetAttribute("cdate", cdate); //存入根节点,保存文件 chat.AppendChild(infor); xmldoc.Save(xmlFilePath); return"恭喜您注册成功!"; } [WebMethod] publicstring readxmlTable() { XmlDocument xmldoc = new XmlDocument(); string xmlFilePath = HttpContext.Current.Server.MapPath("~/data/content.xml"); xmldoc.Load(xmlFilePath); //使用xpath表达式选择文档中所有的tp子节点 XmlNodeList typeNodeList = xmldoc.SelectNodes("/chat/tp"); string str = string.Empty; //定义一个SortedDictionary泛型集合 SortedDictionary<string, string> sd = new SortedDictionary<string, string>(); if (typeNodeList != null) { string cName = string.Empty, age = string.Empty, mobile = string.Empty, email = string.Empty, ads = string.Empty, cdate = string.Empty; foreach (XmlNode tpNode in typeNodeList) { //通过Attributes获得属性名字为cName的属性 cName = tpNode.Attributes["cName"].Value; age = tpNode.Attributes["age"].Value; mobile = tpNode.Attributes["mobile"].Value; email = tpNode.Attributes["email"].Value; ads = tpNode.Attributes["ads"].Value; cdate = tpNode.Attributes["cdate"].Value; sd.Add(cdate, cName + "," + age + "," + mobile + "," + email + "," + ads ); } //foreach (KeyValuePair<string, string> item in sd) 为正序asc //使用泛型集合和linq将时间类型倒序desc排列foreach (KeyValuePair<string, string> item in sd.Reverse()) { str += item.Value + "," + Convert.ToDateTime(item.Key).ToString("yyyy年MM月dd日HH时mm分") + "|"; } } return str.Substring(0, str.Length - 1); } }
原文:http://www.cnblogs.com/Yashull/p/4140763.html
内容总结
以上是互联网集市为您收集整理的.net 泛型集合排序,查找全部内容,希望文章能够帮你解决.net 泛型集合排序,查找所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。