class Account {
public string FirstName { get; private set; } public string LastName { get; private set; } public double Balance { get; private set; } public string AccountNumber { get; private set; }
public Account(string fn, string In, string accnum, double b) {
FirstName = fn;
LastName = In;
AccountNumber = accnum;
Balance = b;
}
}
class OrderbyDemo { static void Main() {
// .
Account[] accounts =
{ new Account("", "", "132CK", 100.23), new Account("", "", "132CD", 10000.00),
new Account("", "", "436CD", 1923.85),
new Account ("", "", "454MM", 987.132),
new Account("", "", "897CD", 3223.19),
new Account("", "", "434CK", -123.32),
new Account("Capa", "", "543MM", 5017.40),
new Account("Capa", "", "547CD", 34955.79),
new Account("Capa", "", "843CK", 345.00),
new Account("", "", "445CK", -213.67), new Account("", "","968MM",5146.67), new Account("", "", "078CD", 15345.99),
new Account("", "", "108CK", 10.98)
};
// // .
// , // , , , var acclnfo = from in accounts
Orderby acc.LastName, acc.FirstName, acc.Balance select acc;
Console.WriteLine(" : "); string str = "";
// , foreach(Account acc in acclnfo) { if(str!= acc.FirstName) {
Console.WriteLine(); str = acc.FirstName;
}
Console.WriteLine("{0}, {l}\tHoMep : {2}, {3,10:C}", acc.LastName, acc.FirstName, acc. AccountNumber, acc.Balance);
}
Console.WriteLine ();
}
}
.
:
, : 108, $10.98
, : 434, ($123.32)
, : 454, $987.13
, : 436CD, $1,923.85
, : 968, $5,146.67
, : 897CD, $3,223.19
, : 445, ($213.67)
, : 078CD, $15,345.99
, : 843, $345.00
, : 543, $5,017.40
, : 547CD, $34,955.79
, : 132, $100.23
, : 132CD, $10,000.00
orderby .
var acclnfo = from in accounts
|
|
Orderby acc.LastName, acc.FirstName, acc.Balance select acc;
. , . , . .
, : 108, $10.98
, : 434, ($123.32)
, : 454, $987.13
, : 436CD, $1,923.85
, , , , .
, descending. , .
var acclnfo = from acc in accounts
Orderby x.LastName, x.FirstName, x.Balance descending select acc;
, .
, : 108, $10.98
, : 436CD, $1,923.85
, : 454, $987.13
, : 434, ($123.32)
, : .
select