SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 128 | Next

Scott Klein

"Professional LINQ"


var query =
from od in orderdetail
where od.SalesOrderID == 43662
select od.UnitPrice;
listbox1.Items.Add(query.Max());
The value returned is 2146.9620. This query can also be written as follows:
var query =
from od in orderdetail
where od.SalesOrderID == 43662
66
Chapter 4: LINQ Standard Query Operators
select od;
listbox1.Items.Add(query.Max(orderDetail => orderDetail.UnitPrice));
There is no performance advantage between the two queries; their use is a matter of user preference
and readability.
Min
On the flip side is the Min operator, which returns the minimum value from a sequence. It also works on
many data types, including decimals, integers, and doubles.
The following example returns the minimum value from the list of provided integers:
List quantity = new List {99, 48, 120, 73, 101, 81, 56};
int cnt = quantity.Min();
listbox1.items.add(cnt);
The value returned from this example is 48. Here??™s an example that returns the minimum unit price of
all the items for a specific order:
var query =
from od in orderdetail
where od.


Pages:
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6