c# - how to write a function that return the min, max value from array of data -
i have seen few solutions on google none of them made sense me, can explain in easy straightforward way how max or min value following situation?
e.g :
let single product can supply many suppliers
1 . supp1 = 1000,1001,1002,1003 (productid's)
2 . supp2 = 1000,1002,1003
3 . supp3 = 1001,1003
and pass 1 ,2 , 3 lists function , 2 output let minqty , maxqty e.g : 1000,1001,1002,1003 out put values 2 , 5
1000,1002,1003 out put values 6 , 3
1001,1003 out put values 4 , 9
with above data want find min , max qty value selected product
output : 1000 = min 2 max 5
1001 = min 2 max 9
1002 = min 2 max 5
1003 = min 2 max 9
can guide me how achieve code sample or logic
highly appreciate
in c# using linq.
public static tuple<t, t> maxandmin<t>(ienumerable<t> values) { return new tuple<t, t>(values.max(), values.min()); } explanation. t generic type , ienumerable take class inherits it. linq .max , .min return max , min respectively. return tuple of max , min.
Comments
Post a Comment