改成这样就可以了。参见下面文章,道理类似
http://www.tek-tips.com/viewthread.cfm?qid=1230578&page=1
public static void Main(string[] args)
{
List<Entity> lu = new List<Entity>();
for (int i = 0; i < 10; i++)
{
User u = new User();
u.Id = i;
u.UserName = getUserName();
u.PassWord = getPassword();
lu.Add(u);
}
lu.Sort();
lu.ForEach(delegate(Entity us)
{
Console.WriteLine("用户Id:" + us.Id + "用户名:" + (us as User).UserName + "密码:" + (us as User).PassWord);
});
Console.Read();
}