select
select . . select . , , , . .
select .* , double.
// select // , double.
Using System; using System.Linq;
class SelectDemo { static void Main() {
double[] nums =
{ -10.0, 16.4, 12.125, 100.85, -2.2, 25.25, -3.5 };
// // , nums. var sqrRoots = from n in nums where n > 0 select Math.Sqrt(n);
Console.WriteLine(" ,\n" + " :");
// , foreach(double in sqrRoots)
Console.WriteLine("{0:#.##}", r);
}
}
.
, :
4.05
3.48
10.04
5.02
select.
Select Math.Sqrt(n);
. Math. Sqrt (), . , , , , nums. , . , select , , .
, select. EmailAddress, . , . , EmailAddress. , , , .
// .
|
|
using System; using System.Linq;
class EmailAddress {
public string Name { get; set; } public string Address { get; set; }
public EmailAddress(string n, string a) {
Name = n;
Address = a;
}
}
class SelectDemo2 { static void Main() {
EmailAddress[] addrs = { new EmailAddress("", "[email protected]"), new EmailAddress ("Tom", "[email protected]"), new EmailAddress("Capa", "[email protected]")
};
//
// .
var eAddrs = from entry in addrs
select entry.Address;
Console.WriteLine(" :");
// , foreach(string s in eAddrs)
Console.WriteLine(" " + s);
}
}
.
:
[email protected] [email protected]
select, select entry.Address;
(Address). , , Email Address. s foreach string. , , , , select.
select , , . . Contactlnfo, , . , Email Addr ess, . Main () Contactlnfo, , , EmailAddress. , , select, EmailAddress, Contactlnfo, .
// // EmailAddresses Contactlnfo.