8,494
社区成员




class Program
{
static void Main(string[] args)
{
List<A> AList = new List<A>() {
new A(){ 单位="a" ,部门="b"},
new A(){ 单位="a1" ,部门="b"}
};
List<B> BList = new List<B>(){
new B(){ 月份="b" },
new B(){ 月份="b1"}
};
var result = from a in AList
from b in BList
select new
{
单位 = a.单位,
部门 = a.部门,
月份 = b.月份
};
var result1 = AList.Join(BList,AList=>1,BList=>1,(x, y) => new {
单位 = x.单位,
部门 = x.部门,
月份 = y.月份
});
}
}
public class A {
public string 单位 { get; set; }
public string 部门 { get; set; }
}
public class B
{
public string 月份 { get; set; }
}
static void Main(string[] args)
{
DataTable table1 = new DataTable();
table1.Columns.Add("单位", typeof(string));
table1.Columns.Add("部门", typeof(string));
table1.Rows.Add("A1", "B1");
table1.Rows.Add("A1", "B2");
table1.Rows.Add("A1", "B3");
table1.Rows.Add("A2", "C1");
table1.Rows.Add("A2", "C2");
table1.Rows.Add("A2", "C3");
table1.Rows.Add("A2", "C4");
DataTable table2 = new DataTable();
table2.Columns.Add("月份", typeof(string));
table2.Rows.Add("1月");
table2.Rows.Add("2月");
table2.Rows.Add("3月");
var result = from a in table1.AsEnumerable()
from b in table2.AsEnumerable()
select new
{
单位 = a.Field<string>("单位"),
部门 = a.Field<string>("部门"),
月份 = b.Field<string>("月份")
};
Console.WriteLine(result.Count().ToString());
Console.ReadKey();
}
那你是这个意思么