首页 > 编程语言 >C#------LINQ查询(一)

C#------LINQ查询(一)

时间:2024-09-18 13:51:53浏览次数:1  
标签:StudentName C# StudentScore LINQ 查询 int score ------ public

1.查询一定范围数字

        static void QueryInt()
        {
            // Specify the data source.
            int[] scores = { 97, 92, 81, 60 };

            // Define the query expression.
            IEnumerable<int> scoreQuery =
                from score in scores
                where score > 90
                select score;

            // Execute the query.
            foreach (int i in scoreQuery)
            {
                Console.Write(i + " ");
            }

            // Output: 97 92
        }

2.查询包含指定字符的字符

        static void QueryString()
        {
            // Specify the data source.
            string[] scores = { "SU001", "SU003", "EFUN", "ECHO" };

            // Define the query expression.
            IEnumerable<string> scoreQuery =
                from score in scores
                where score.StartsWith("SU")
                select score;

            // Execute the query.
            foreach (string i in scoreQuery)
            {
                Console.Write(i + " ");
            }

            // Output: SU001  SU003
        }

3.查询指定条件对象

    public class StudentScore
    { 
        public string StudentName { get; set; }

        public int MathScore { get; set; }

        public int EnglishScore { get; set; }

        public int ChineseScore { get; set; }


    }
        static void Main(string[] args)
        {
            //QueryInt();
            //QueryString();

            List<StudentScore> students = new List<StudentScore> 
            { 
                new StudentScore(){StudentName="SU001",MathScore=95,EnglishScore = 100,ChineseScore = 99},
                new StudentScore(){StudentName="SU003",MathScore=100,EnglishScore=100,ChineseScore=88},
                new StudentScore(){StudentName="S0004",MathScore=80,EnglishScore=80,ChineseScore=90}
            };

            //查询所有SU学生
            IEnumerable<StudentScore> studentQuery = from student in students
                                                     where student.StudentName.StartsWith("SU")
                                                     select student;
            //打印学生
            foreach (StudentScore s in studentQuery)
            {
                Console.WriteLine(s.StudentName);
            }


        }

 

标签:StudentName,C#,StudentScore,LINQ,查询,int,score,------,public
From: https://www.cnblogs.com/echo-efun/p/18418357

相关文章

  • 豌豆群体基因组撞车NG了?
    首个豌豆大规模群体基因组与GWAS见刊今天,浙江省农科院与浙江大学联合在NatureGenetics(NG)上发表豌豆群体基因组文章:ReferencegenomesequenceandpopulationgenomicanalysisofpeasprovideinsightsintothegeneticbasisofMendelianandotheragronomictraits。首次......
  • 【每日一题】LeetCode 2332.坐上公交的最晚时间(数组、双指针、二分查找、排序)
    【每日一题】LeetCode2332.坐上公交的最晚时间(数组、双指针、二分查找、排序)题目描述给你一个下标从0开始长度为n的整数数组buses,其中buses[i]表示第i辆公交车的出发时间。同时给你一个下标从0开始长度为m的整数数组passengers,其中passengers[j]表示第......
  • Liftoff:基于参考基因组的基因组注释
    Liftoff是一个可以准确根据同一物种或近缘物种基因组进行基因注释映射的工具(与liftOver进行不同基因组版本的染色体位置转换有点类似)。该工具仅需两个基因组序列和参考基因组的基因注释文件即可进行基因注释。Liftoff使用minimap2将参考基因组的基因序列与目标基因组比对,这样的好......
  • 智能水肥一体化:农业现代化的新趋势
    在信息技术迅速发展的今天,传统农业面临着前所未有的挑战和机遇。智能水肥系统作为创新的农业技术之一,逐渐成为提升农业生产效率和可持续发展的重要手段。本文将围绕智能水肥一体化进行深入探讨,帮助大家更好地理解这一新兴领域。1.什么是智能水肥一体化?智能水肥一体化是指将......
  • 质量管理专家要求
    参与研发效能体系、过程质量保障体系的建设与改进工作;参与公司级质量工具平台的设计、开发与运营; 职责:对整体集团级产研体系质量目标和保障工作负责参与稳定性保障的建设与改进工作负责设计、落地各类业务的稳定性保障解决方案。包含不限制于:线上问题管理、全维度全链路......
  • Nature Comm. | CoPheScan:一种考虑连锁不平衡的全表型组关联分析
    分享一篇最近发表在NC的一篇文章:CoPheScan:phenome-wideassociationstudiesaccountingforlinkagedisequilibrium。文章介绍了一种新的贝叶斯方法CoPheScan(ColocadaptedPhenome-wideScan),用于在考虑连锁不平衡(LD)的情况下进行表型范围关联研究(Phenome-wideassociationstud......
  • 56.【C语言】字符函数和字符串函数(strtok函数)(未完)
    目录12.strtok函数(较复杂)*简单使用总结:*优化12.strtok函数(较复杂)*简单使用strtok:stringintotokenscplusplus的介绍点我跳转翻译:函数strtokchar*strtok(char*str,constchar*delimiters);总结:delimiters参数指向一个字符串,定义了用......
  • 几种提升turtle绘图速度的方法
    问题来源最近老师要求设计程序模拟伽尔顿板。程序设计还是很简单的只需在每次下落时从[0,1]之间产生一个随机整数,若为零则向左反之向右,并用一个变量来记录向右的次数以确定小球的最终出口。但是为了准确性,要投成千上万次,看着小乌龟慢慢爬。。。。光绘制10层柱子都要1分钟。......
  • 何为快速育种(Speed Breeding)?
    所谓“SpeedBreeding”(简称“SB”,额~),就是在环境可控的人工气候室中,通过改变光周期来加速植物的生长周期,从而起到加速育种的目的。快速育种:加速作物研究和育种的强大工具2017年7月9日,澳大利亚昆士兰大学LeeHickey团队领衔在预印本网站bioRxiv上发表了“SpeedBreeding”技术的详细......
  • 31263 / 32004 Game Development
    31263/32004GameDevelopmentLabWeek6GettingStarted1.Downloadthecorrespondingweek’szipfilefromthisweek’smoduleonCanvas.2.UnziptheprojectfolderandopenitinUnity.Ifthereareanywarningsaboutdifferenceinversions,justconti......