1

我有一个这种类型的对象列表:

MyObject
  .StartDate
  .EndDate
  .Number

对于每个对象,我想返回两个对象:

NewObject
  .Date
  .Number

在其中一个对象中,日期将是 EndDate 和 Number。另一个对象 Date 将是 StartDate 并且 Number 将是负数

4

3 回答 3

3
MyObjects.SelectMany(o => new[] { 
    new NewObject { Date = o.EndDate, Number = o.Number },
    new NewObject { Date = o.StartDate, Number = -o.Number } } );
于 2013-07-25T11:17:22.803 回答
0
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 });
于 2013-07-25T11:17:14.313 回答
0
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
            }
        };
于 2013-07-25T11:24:03.460 回答