再來,為它加點意義:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ_EX1
{
class Program
{
static void Main(string[] args)
{
// CREATE ARRAY TO FOR TESTING
PersonB[] people = {
new PersonB { Name="Allen Frances", Age=11},
new PersonB { Name="Burke Madison", Age=50},
new PersonB { Name="Connor Morgan", Age=59},
new PersonB { Name="David Charles", Age=33},
new PersonB { Name="Everett Frank", Age=16}
};
// USE LINQ TO CHECK THE ITEMS WHICH NEEDED TO UPDATE
var query = from myPerson in people
where myPerson.Age == 11
select myPerson;
// UPDATE OR ADD NEW VALUE INTO THAT OBJECT
foreach (var item in query)
item.otherValue = "<<<Allen FUXK>>>";
foreach (var newPeople in people)
{
Console.WriteLine("{0} is {1} years old, and their new value is {2} ...",
newPeople.Name,
newPeople.Age,
newPeople.otherValue
);
}
Console.ReadLine();
}
}
/*================================
*
* NEW DATA OBJECT CLASS PERSON FOR SYSTEM TEST
*
================================ */
public class Person
{
public string Name{get; set;}
public int Age{get; set;}
}
public class PersonB: Person
{
public string otherValue{get; set;}
}
}
Object在C#裡很好用! 您看完每個用法, 最好也給他多點練習!