核心代码:
using System;
using System.Collections.Generic;
using System.Linq;
namespace 查询运算符
{
class Program
{
static void Main(string[] args)
{
List<PersonClass> personList = new List<PersonClass>()
{
new PersonClass("刘一手",18,"男"),
new PersonClass("李四",32,"男"),
new PersonClass("王五",23,"男"),
};
personList = personList.Where(p => p.sex == "男" && p.age > 30).ToList();
//方法一: for循环方法
//for(int i = 0; i < personList.Count; i++)
//{
// Console.WriteLine($"姓名:{personList[i].name}, 年龄:{personList[i].age }, 性别:{personList[i].sex}" );