关于LINQ的一个问题!疑点看红色字体这行!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linq1
{
public class linq2
{
public string firstname { get; set; }
public string lastname { get; set; }
public string emailaddress { get; set; }
public override string ToString()
{
return string.Format("{0} {1}\nemail: {2}", firstname, lastname, emailaddress);
}
}
class Program
{
static void Main(string[] args)
{
List<linq2> customers=createcustomerlist();
IEnumerable<linq2> result = from customer in customers where customer.firstname == "donna" select customer;
Console.WriteLine("firstname==\"donna\"");
foreach(linq2 customer in result)
{
Console.WriteLine(customer.ToString());
}
customers[3].firstname = "donna";//
为什么这里赋值后,result这个变量也改了呢!是不是又自动执行了上面Ienumerable<linq2>这行; Console.WriteLine("firstname=\"donna\"(take two)");
foreach (linq2 customer in result)
{
Console.WriteLine(customer.ToString());
}
}
private static List<linq2> createcustomerlist()
{
List<linq2> customer5=new List<linq2>
{
new linq2{firstname="orlando",lastname="gee",emailaddress="orlando@adventure.com"},
new linq2{firstname="donna",lastname="carreras",emailaddre