Sixth time Assignment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.