如何编写文本(文本文档怎么编程序)

导读 ublic class Person : IComparable { public DateTime time; public string name; ...

ublic class Person : IComparable { public DateTime time; public string name; #region IComparable 成员 public int CompareTo(Person other) { return this.time.CompareTo(other.time); } #endregion } class Program { static void Main(string[] args) { string s = @"0时0分14秒 玩家10时0分29秒 玩家20时0分1秒 玩家30时0分34秒 玩家40时0分4秒 玩家50时0分5秒 玩家60时0分49秒 玩家70时0分30秒 玩家8"; List lst = new List(); Regex r = new Regex("(?[\S]+)[\s]+(?[\S]+)"); Match m = r.Match(s); while (m.Success) { Person p = new Person(); p.time = DateTime.Parse(m.Groups["t"].Value); p.name = m.Groups["u"].Value; lst.Add(p); m = m.NextMatch(); } //排序操作。

只有泛型集合中的对象实现了IComparable接口才能进行排序。

lst.Sort(); foreach (Person item in lst) { Console.WriteLine(***.name + ":" + string.Format("{0:HH时MM分ss秒}", item.time)); } Console.WriteLine("Finish!!!"); Console.ReadKey(); }如果你是初学者,估计你看这段代码是会有困难的。

免责声明:本文由用户上传,如有侵权请联系删除!