Obtaining the min and max of a two-dimensional array using LINQ

前端 未结 4 2499
醉酒成梦
醉酒成梦 2021-02-20 09:30

How would you obtain the min and max of a two-dimensional array using LINQ? And to be clear, I mean the min/max of the all items in the array (not the min/max of a particular di

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 10:07

    Since Array implements IEnumerable you can just do this:

    var arr = new int[2, 2] {{1,2}, {3, 4}};
    int max = arr.Cast().Max();    //or Min
    

提交回复
热议问题