• 第六次作业


    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);
    }
    }

  • 相关阅读:
    菜单栏与功能工具栏
    信息与编码
    opencv颜色体系认知
    团队-科学计算器-开发文档
    CSS3动画
    Font Awesome 4.0.3 字体图标完美兼容IE7
    Bootstrap+Thinkphp3.2+Auth认证+jquery-validator后台
    Wordpress主题中常用代码总结
    Wordpress 常用代码解释
    wordpress一些常用代码
  • 原文地址:https://www.cnblogs.com/zeromaiko/p/4461139.html
Copyright © 2020-2023  润新知