码迷,mamicode.com
首页 > 其他好文 > 详细

LIST<>泛型集合取得对象的属性值

时间:2016-06-30 08:40:47      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CacheTest
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Customer> list = new List<Customer>()
            {
                new Customer() { ID = "A", Name = "AA", TaxNo = 1 },
                new Customer() { ID = "B", Name = "BB", TaxNo = 2 },
                new Customer() { ID = "C", Name = "CC", TaxNo = 3 }
            };

            foreach (var item in list)
            {
                string name = item.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, item, null) as string;
                Response.Write(name + "\n");
            }
        }
    }

    public class Customer
    {
        public string ID { get; set; }

        public string Name { get; set; }

        public int TaxNo { get; set; }
    }
}

  

LIST<>泛型集合取得对象的属性值

标签:

原文地址:http://www.cnblogs.com/wolfocme110/p/5628785.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!