找回密码
 立即注册

QQ登录

只需一步,快速开始

工控课堂 首页 工控文库 上位机编程 查看内容

C# Linq 查找 List<> 集合元素

2021-11-8 21:06| 发布者: gk-auto| 查看: 1435| 评论: 0

摘要: C# Linq 查找 List 集合元素static void Main(string args){ListStudent students = new ListStudent{new Student {Name="Tom", Score=50},new Student {Name="Mark", Score=80},new Student {Name="Alice", Score=7 ...
C# Linq 查找 List<> 集合元素
static void Main(string[] args)
{
    List<Student> students = new List<Student>{
        new Student {Name="Tom", Score=50},
        new Student {Name="Mark", Score=80},
        new Student {Name="Alice", Score=70},
    };
 
    // 查找条件
    var query = from student in students
                where student.Name == "Mark"
                select student;
 
    // 输出查找结果
    foreach (Student item in query)
    {
        Console.WriteLine(item.Name + " - " + item.Score);
    }
 
    Console.Read();
}
 
class Student
{
    /// <summary>
关注公众号,加入500人微信群,下载100G免费资料!
发表评论

最新评论

热门文章
关闭

站长推荐上一条 /1 下一条

QQ|手机版|免责声明|本站介绍|工控课堂 ( 沪ICP备20008691号-1 )

GMT+8, 2025-12-22 19:17 , Processed in 0.367301 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.