我有一个这种类型的对象列表:
MyObject
.StartDate
.EndDate
.Number
对于每个对象,我想返回两个对象:
NewObject
.Date
.Number
在其中一个对象中,日期将是 EndDate 和 Number。另一个对象 Date 将是 StartDate 并且 Number 将是负数
我有一个这种类型的对象列表:
MyObject
.StartDate
.EndDate
.Number
对于每个对象,我想返回两个对象:
NewObject
.Date
.Number
在其中一个对象中,日期将是 EndDate 和 Number。另一个对象 Date 将是 StartDate 并且 Number 将是负数
MyObjects.SelectMany(o => new[] {
new NewObject { Date = o.EndDate, Number = o.Number },
new NewObject { Date = o.StartDate, Number = -o.Number } } );
var result = (from myObject in MyObjects
select new NewObject { Date = myObject.StartDate, Number = -myObject.number }).Concat
(from myObject in MyObjects
select new NewObject { Date = myObject.EndDate, Number = myObject.number });
var q = from o in MyObjects
select new {
NewObject1 = new NewObject(){
Date = o.StartDate,
Number = -o.Number
},
NewObject2 = new NewObject(){
Date = o.EndDate,
Number = o.Number
}
};