0

次のコードがあります。

var workOrderList = new List<WorkOrder>(
               from index in Enumerable.Range(1, orders.Length)
               select new WorkOrder
               {
                   OrderID = orders[index - 1],
                   Status = status[random.Next(0,status.Length-1)],
                   TotalQuantity = random.Next(1, 5) * 8,
                   ScheduleCollection = new ObservableCollection<Schedule>
                   {
                     new Schedule
                       {
                           Color = colors[random.Next(0,colors.Length-1)],
                           Model = models[random.Next(0,models.Length-1)],
                           Status = status[random.Next(0,status.Length-1)],
                           TotalNumber = To be Updated bases on Total Quantity
                       }
}

ここで、 TotalQuantity から値を除算または減算して Total Number を更新したいと考えています。

4

1 に答える 1

1

letクエリで句を使用して、一般的な式を抽出します。

var workOrderList = new List<WorkOrder>(
    from index in Enumerable.Range(1, orders.Length)
    let totalQuantity = random.Next(1, 5) * 8
    select new WorkOrder
    {
        OrderID = orders[index - 1],
        Status = status[random.Next(0,status.Length-1)],
        TotalQuantity = totalQuantity,
        ScheduleCollection = new ObservableCollection<Schedule>
        {
          new Schedule
            {
                Color = colors[random.Next(0,colors.Length-1)],
                Model = models[random.Next(0,models.Length-1)],
                Status = status[random.Next(0,status.Length-1)],
                TotalNumber = // Do something with totalQuantity
            }
        }
    });
于 2012-11-23T09:28:24.997 に答える