我有三个不同类型的列表:
List<Customer> customerList = new List<Customer>();
List<Product> productList = new List<Product>();
List<Vehicle> vehicleList = new List<Vehicle>();
Run Code Online (Sandbox Code Playgroud)
我也有这个清单
List<string> stringList = {"AND","OR"};
Run Code Online (Sandbox Code Playgroud)
由于第一个元素stringList是AND我想用customerList和做内连接productList.然后我想vehicleList 与结果进行正确的连接,例如:
from cust in customerList
join prod in productList on cust.ProductId equals prod.Id
join veh in vehicleList on prod.VehicleId equals veh.Id into v
from veh in v.DefaultIfEmpty()
select new {customerName = cust.Name, customerVehicle=veh.VehicleName}
Run Code Online (Sandbox Code Playgroud)
我想以自动化的方式制作它,假设我有N多个列表和s和s的N-1数量,我该如何加入它们?此外,可以有许多相同类型的列表.这样的事情甚至可能吗?如果不是我能做些什么来使它更接近我的需要?提前致谢.ANDOR
编辑:我在这样的字典中持有列表及其类型:
var listDict = new Dictionary<Type, object>();
Run Code Online (Sandbox Code Playgroud)
所以如果有必要,我可以在这个字典里面迭代.
我正试图找到与LINQ的交叉点.
样品:
List<int> int1 = new List<int>() { 1,2 };
List<int> int2 = new List<int>();
List<int> int3 = new List<int>() { 1 };
List<int> int4 = new List<int>() { 1, 2 };
List<int> int5 = new List<int>() { 1 };
Run Code Online (Sandbox Code Playgroud)
想要返回:1,因为它存在于所有列表中..如果我运行:
var intResult= int1
.Intersect(int2)
.Intersect(int3)
.Intersect(int4)
.Intersect(int5).ToList();
Run Code Online (Sandbox Code Playgroud)
它返回什么,因为1显然不在int2列表中.无论一个列表是否为空,如何使其工作?
使用上面的例子或:
List<int> int1 = new List<int>() { 1,2 };
List<int> int2 = new List<int>();
List<int> int3 = new List<int>();
List<int> int4 = new List<int>();
List<int> int5 = new List<int>();
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何返回1和2 ..如果列表已填充,我不知道提前...