例如:一个实体类Person ,如何将IList<Person>直接赋给IList<object>

解决方案 »

  1.   

    IList <Person> persons;
    IList <object> objects;foreach(Person p in persons)
    {
       objects.Add(p);
    }  
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication18
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            IList<Person> persons = new List<Person>();            persons.Add(new Person("1"));
                persons.Add(new Person("2"));
                persons.Add(new Person("3"));            IList<object> objects = new List<object>(persons.ToArray());            foreach (Person P in objects)
                    MessageBox.Show(P.Name); 
            }        class Person
            {
                public String Name = String.Empty;            public Person(String Name)
                {
                    this.Name = Name;
                }
            }
        }
    }
      

  3.   

    IList <Person> p=new IList <Person>(); foreach(Person p in persons)
    {
    }直接赋值
      

  4.   

    ((List<object>)list2).AddRange(list1);
      

  5.   

    如果实体IList数据量非常大的话,比如说10w,20w条数据,循环赋值是不是要浪费很多时间啊
      

  6.   

    10W,20W你放到List里面???这种转换的目的是什么?
      

  7.   

    多个实体IList调用一个赋值方法