using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<StudentScore> lists = new List<StudentScore>();
for (int i = 0; i < 10; i++) {
lists.Add(new StudentScore("lzx"));
lists.Add(new StudentScore("llzx1"));
lists.Add(new StudentScore("llzx2"));
lists.Add(new StudentScore("lzx3"));
}
Console.WriteLine("添加數據完成");
//var data1=from student in lists where student.Name.Contains("1") select student;//Linq用法
var data2 = lists.Where(n => n.Name.Contains("1")).ToList();//Lambda表達式用法
Console.WriteLine(data2.Count());
Console.ReadLine();//可用令命令窗口不馬上自動關閉
}
public class StudentScore
{
public StudentScore(string Name) {
this.Name=Name;
}
public StudentScore( )
{
}
public string Name { get; set; }
public string Gender { get; set; }
public int Age { get; set; }
public string Major { get; set; }
public int Score { get; set; }
}
}
}