zoukankan      html  css  js  c++  java
  • 第六次作业

    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//指定范围变量和数据源 customers

    where customer.FirstName == "Donna" select customer;

    List<Customer> cachedResult = result.ToList<Customer>();//如果你想缓存结果,这样它就可以加工后无需重新制作查询,

    //你可以用ToList方法或ToArray()方法来保存结果的副本。

    Console.WriteLine("FirstName == "Donna"");

    foreach (Customer customer in result)

    {

    Console.WriteLine(customer.ToString());

    }

    customers[3].FirstName = "Donna";

    Console.WriteLine("FirstName == "Donna" (take two)");

    foreach (Customer customer in result)
    {
    Console.WriteLine(customer.ToString());
    Console.ReadLine();
    }//将第四个对象的First name改为Donna并输出
    }


    private static List<Customer> CreateCustomerList()

    {

    List<Customer> customers = new List<Customer>

    { new Customer

    { FirstName = "Orlando",LastName = "Gee", EmailAddress = "orlando0@adventure-works.com"},

    new Customer { FirstName = "Keith", LastName = "Harris", EmailAddress = "keith0@adventure-works.com" },

    new Customer { FirstName = "Donna", LastName = "Carreras", EmailAddress = "donna0@adventure-works.com" },

    new Customer { FirstName = "Janet", LastName = "Gates", EmailAddress = "janet1@adventure-works.com" },

    new Customer { FirstName = "Lucy", LastName = "Harrington", EmailAddress = "lucy0@adventure-works.com" } };

    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} Email: {2}",
    FirstName, LastName, EmailAddress);
    }
    }

  • 相关阅读:
    「ROI 2019 Day1」运输 20/19
    「ROI 2018 Day 2」无进位加法
    「ROI 2018 Day 1」量子隐形传态
    「ROI 2018 Day 2」快速排序
    「ROI 2018 Day 1」Innophone (分块+斜率优化)
    「ROI 2017 Day 1」虎 (计算几何)
    [BJ United Round #3] 押韵 [学习笔记]
    「CEOI2020」象棋世界
    CF1375G
    CF1392(div1+div2)
  • 原文地址:https://www.cnblogs.com/zeromaiko/p/4461139.html
Copyright © 2011-2022 走看看