我有2个iCollections如下: -
ICollection 1
public class ClassA : List<ClassC>, IEnumerable<SqlDataRecord>
{
IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator()
{
var sdr = new SqlDataRecord(
new SqlMetaData("A", System.Data.SqlDbType.Int)
);
foreach (ClassC ei in this)
{
sdr.SetInt32(0, ei.A);
yield return sdr;
}
}
}
ICollection 2
public class ClassB : List<ClassC>, IEnumerable<SqlDataRecord>
{
IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator()
{
var sdr = new SqlDataRecord(
new SqlMetaData("A", System.Data.SqlDbType.Int),
new SqlMetaData("B", System.Data.SqlDbType.Int)
);
foreach (ClassC ei in this)
{
sdr.SetInt32(0, ei.A);
sdr.SetInt32(0, ei.B);
yield return sdr;
}
}
}
如何将ClassB的数据传递给ClassA,即ICollection 2和ICollection 1?
此致 阿布舍克巴克
答案 0 :(得分:0)
ClassA a = new ClassA();
ClassB b = new ClassB();
// fill a and b
a.AddRange(b);
或者我错过了什么?