C# 将列表linq表达式转换为定义的列表类
你有这门课吗C# 将列表linq表达式转换为定义的列表类,c#,.net,vb.net,linq,lambda,C#,.net,Vb.net,Linq,Lambda,你有这门课吗 私有类MyClass 公共属性propertyOne()作为字符串 公共属性propertyTwo()作为字符串 公共属性propertyN()为整数 末级 现在我想从lambda或linq表达式中填充MyClass的列表,其中一些类似于 Dim myClassList作为新列表(MyClass的) myClassList=(来自MyOtherList1.GetAll()中的LotusList1) 在lOtherList1.Id上的MyOterhList2.GetAll()中加入
私有类MyClass
公共属性propertyOne()作为字符串
公共属性propertyTwo()作为字符串
公共属性propertyN()为整数
末级
现在我想从lambda或linq表达式中填充MyClass的列表,其中一些类似于
Dim myClassList作为新列表(MyClass的)
myClassList=(来自MyOtherList1.GetAll()中的LotusList1)
在lOtherList1.Id上的MyOterhList2.GetAll()中加入lOtherList2等于lOtherList2.Id
选择myClassList.Add(使用{.propertyOne=lOtherList1.Field1,
.propertyTwo=lOtherList1.Field2,
.propertyN=lOtherList2.Field1}).Tolist()
但是我得到了这个错误“表达式不产生值”,我是怎么做的?
myClassList。添加
是查询中错误的部分,请按如下方式编辑它:
Dim myClassList as new List(Of MyClass)
myClassList = (From lOtherList1 in MyOtherList1.GetAll()
join lOtherList2 in MyOterhList2.GetAll()
on lOtherList1.Id Equals lOtherList2.Id
Select new MyClass With
{
.propertyOne = lOtherList1.Field1,
.propertyTwo = lOtherList1.Field2,
.propertyN = lOtherList2.Field1
})).Tolist()
您将执行以下操作:
myClassList = (From lOtherList1 in MyOtherList1.GetAll()
Join lOtherList2 in MyOtherList2.GetAll()
On lOtherList1.Id Equals lOtherList2.Id
Select new MyClass With
{
.propertyOne = lOtherList1.Field1,
.propertyTwo = lOtherList1.Field2,
.propertyN = lOtherList2.Field1
}).ToList()
你几乎得到了正确的代码。您只需删除对myClassList.Add()
的调用