0

6 列のデータテーブルがあり、各行の最小値を見つける必要があります。これはどのように行うことができますか?

Col1 Col2 Col3 Col4 Col5 Col6 Min
45   41   24   25   74   145  24
27   28   398  82   2    54   2
5   563    7   20   43   254  5
4

3 に答える 3

3
var result = dt.AsEnumerable()
               .Select(row => row.ItemArray.Cast<int>().Min());
于 2013-06-06T10:21:26.683 に答える
2

これを試して、

List<int> result = new List<int>();
foreach (DataRow row in table.Rows)
{
    result.Add(row.ItemArray.Cast<int>().Min());
}
于 2013-06-06T10:19:38.817 に答える
0
dataTable.Select(row => Math.Min(Math.Min(Math.Min(Math.Min(Math.Min(row.Col1, row.Col2), row.Col3), row.Col4), row.Col5), row.Col6));

また

dataTable.Select(row => new int[] { row.Col1, row.Col2, row.Col3, row.Col4, row.Col5, row.Col6 }).Select(intArray => intArray.Min());

または短縮:

dataTable.Select(row => (new int[] { row.Col1, row.Col2, row.Col3, row.Col4, row.Col5, row.Col6 }).Min()));

また

dataTable.Select(row => row.ItemArray.Cast<int>().Min());

または、dataTable に int ではない他の列が含まれている場合:

dataTable.Select(row => row.ItemArray.OfType<int>().Min());
于 2013-06-06T10:19:50.827 に答える