От: | Rikomer | ||
Дата: | 30.10.16 09:22 | ||
Оценка: |
Полноценный пример | |
using System; using System.Linq; using System.Collections.Generic; using System.IO; using ConsoleApplication3; class Solution { static void Main(String[] args) { var a1 = new MonthData2 { Month = "1", DataAmt = 10.00m, DataQty = 20 }; var a2 = new MonthData2 { Month = "1", DataAmt = 20.00m, DataQty = 30 }; var a3 = new MonthData2 { Month = "1", DataAmt = 30.00m, DataQty = 40 }; var arr = new List<MonthData2>(); arr.AddRange(new[] { a1, a2, a3 }); var x = 1; var arr2 = arr.Select(a => new MonthData(a.Month, x != 1 ? (Decimal?)a.DataAmt : (Int32?)a.DataQty)) .ToList(); Console.ReadLine(); } public class MonthData { public MonthData(String Month, Int32? DataQty) { this.Month = Month; this.DataQty = DataQty; } public MonthData(String Month, Decimal? DataAmt) { this.Month = Month; this.DataAmt = DataAmt; } public readonly String Month; public readonly Int32? DataQty; public readonly Decimal? DataAmt; } public class MonthData2 { public String Month; public Int32? DataQty; public Decimal? DataAmt; } } | |
От: | kov_serg | ||
Дата: | 30.10.16 09:28 | ||
Оценка: | +1 |
var arr2 = arr.Select(a=> x!=1
? new MonthData(a.Month,(Decimal?)a.DataAmt)
: new MonthData(a.Month,(Int32?)a.DataQty)
).ToList();
От: | TK | кывт.рф | |
Дата: | 30.10.16 14:26 | ||
Оценка: | +1 |
От: | Mr.Delphist | ||
Дата: | 31.10.16 14:28 | ||
Оценка: | +1 |