using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Data; namespace TestList { class Program { static void Main(string[] args) { List<DateTime> list = new List<DateTime>(); List<string> list2 = new List<string>(); for(int i=1 ;i<=30;i++) { DateTime TestTime = new DateTime(2009,11,i); list.Add(TestTime); } Action<DateTime> trace = delegate(DateTime DValue) { DValue = DValue.AddMonths(1);//加一個月 //寫入Trace Trace.WriteLine(DValue); //將資料寫入屬性 Trace.Listeners[0].Attributes.Add(DValue.ToString("yyyyMMdd"), DValue.ToString("yyyyMMdd")); //Console.WriteLine(DValue.ToString("yyyyMMdd")); }; Predicate<DateTime> isPrime = delegate(DateTime DValue) { //當日期為偶數為真反之為否 return (DValue.Day % 2 == 0) ? true : false; }; list.ForEach(trace); List<DateTime> primes = list.FindAll(isPrime); foreach (DateTime temp in list) Console.WriteLine( Trace.Listeners[0].Attributes[temp.AddMonths(1).ToString("yyyyMMdd")].ToString()); foreach (DateTime temp in primes) Console.WriteLine(temp.ToString("yyyyMMdd")); Console.ReadLine(); } } }