1. 程式人生 > >在多執行緒中使用匿名類通過反射獲取其屬性值

在多執行緒中使用匿名類通過反射獲取其屬性值

標題挺彆扭的,至少我對這些高階技術瞭解的還很少,繼續學習吧...初次接觸匿名類感覺很爽,簡化了程式碼量(可能有些時候還真需要它)

控制檯的程式碼

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread t = new Thread(new ParameterizedThreadStart(SayHolle));
            t.Start(new { Name = "Seven", Age = 24 });
        }

        static public void SayHolle(Object o)
        {
            Console.WriteLine("Hello! My Name is {0} and My age is {1}",
                o.GetType().GetProperty("Name").GetValue(o,null),
                o.GetType().GetProperty("Age").GetValue(o,null));
        }
    }
}