Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Linq;
Using System.Collections.Generic;
Namespace ConsoleApplication8
{
Class Program
{
static void Main (string[] args)
{
List<customer> customers = Createcustomerlist (); Find Customer by First name
ienumerable<customer> result = from Customer in customers//specify range variable and data source customers
where customer. FirstName = = "Donna" SELECT customer;
list<customer> Cachedresult = result. Tolist<customer> ();//If you want to cache the results so that it can be processed without having to re-create the query,
You can use the ToList method or the ToArray () method to save a copy of the result.
Console.WriteLine ("FirstName = = \" Donna\ "");
foreach (Customer customer in result)
{
Console.WriteLine (Customer. ToString ());
}
CUSTOMERS[3]. FirstName = "Donna";
Console.WriteLine ("FirstName = = \" Donna\ "(Take)");
foreach (Customer customer in result)
{
Console.WriteLine (Customer. ToString ());
Console.ReadLine ();
}//changes the first name of the fourth object to Donna and outputs
}
private static list<customer> createcustomerlist ()
{
List<customer> customers = new list<customer>
{New Customer
{FirstName = "Orlando", LastName = "Gee", EmailAddress = "[Email protected]"},
New Customer {FirstName = "Keith", LastName = "Harris", EmailAddress = "[Email protected]"},
New Customer {FirstName = "Donna", LastName = "Carreras", EmailAddress = "[Email protected]"},
New Customer {FirstName = "Janet", LastName = "Gates", EmailAddress = "[Email protected]"},
New Customer {FirstName = "Lucy", LastName = "Harrington", EmailAddress = "[Email protected]"}};
return customers;
}
}
}
public class Customer
{
public string FirstName {get; set;}
public string LastName {get; set;}
public string EmailAddress {get; set;}
Overrides the object.tostring () to provide a
String representation of the object properties.
public override string ToString ()
{
return string. Format ("{0} {1}\nemail: {2}",
FirstName, LastName, EmailAddress);
}
}
Sixth time Assignment