从数组中取值,并且比较字符串的值

从list中取出年份小于2010月份小于10的字符串以及它的位置:
private
static void GetValue() { List<string> list = new List<string>(); list.Add("2010-8-frist"); list.Add("2008-12-second"); list.Add("2012-9-third"); for (int i = 0; i < 3; i++) { if (Convert.ToInt16(list[i].Substring(0, list[i].IndexOf('-'))) < 2010) { Console.WriteLine("{0},{1}", i, list[i]); } else if ((Convert.ToInt16(list[i].Substring(0, list[i].IndexOf('-'))) == 2010)) { if (Convert.ToInt16(list[i].Substring(list[i].IndexOf('-') + 1, list[i].LastIndexOf('-') - list[i].IndexOf('-') - 1)) < 10) { Console.WriteLine("{0},{1}", i, list[i]); } } } }
posted @ 2012-11-14 13:40  威少  阅读(454)  评论(0编辑  收藏  举报