zoukankan      html  css  js  c++  java
  • LInQ的一些查询

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using LinQ.Models;
    
    namespace LinQ
    {
        class Program
        {
            static void Main(string[] args)
            {
                //1.查询东京的学生
                
                List<Student> StuList = Student.GetStudentList();
                //stu 数据范围?,StuList数据源
                //select * from tableName
                var stuQuery = from stu in StuList
                               where stu.studentCity == "东京"
                               select stu;
                foreach (var item in StuList)
                {
                    Console.WriteLine("姓名{0},城市{1},性别{2}",item.studentName,item.studentCity,item.studentSex);
                }
    
    
                Console.WriteLine("---------查询单个属性---姓名--------------------");
    
                //查询单个属性
                var stuQueryName = from stu in StuList
                                   where stu.studentCity == "东京"
                                   select stu.studentName;
    
                foreach (var item in stuQueryName)
                {
                    Console.WriteLine("姓名{0}", item);
                }
    
                Console.WriteLine("---------查询多个属性--------");
                //查询多个属性
                var temp = from stu in StuList
                           where stu.studentCity == "东京"
                           select new {id=stu.studentID,name=stu.studentName,stu.studentCity };
    
                foreach (var item in temp)
                {
                    Console.WriteLine("id:{0},姓名{1},城市{2}",item.id,item.name,item.studentCity);
                }
    
                //连接查询
                Console.WriteLine("-------连接查询-------");
                DemoJoinOn();
    
                Console.ReadKey();
            }
            public static void DemoJoinOn()
            {
                
                var temp = from stu in Student.GetStudentList()
                           join teach in Teacher.GetTeacherList()
                           on stu.teacherID equals teach.teacherID
                           select new { stu.studentName, teach.teacherName };
    
                foreach (var item in temp)
                {
                    Console.WriteLine("学生姓名:{0},老师姓名{1}",item.studentName,item.teacherName);
                }
            }
        }
    }
  • 相关阅读:
    一个没调好的程序
    bzoj1214 [HNOI2004]FTP服务器
    bzoj4514 [Sdoi2016]数字配对(网络流)
    二分图最大权匹配模板(pascal)
    CSS控制文字,超出部分显示省略号
    新型智慧城市顶层设计经验分享
    移动端浏览器前端优化
    桌面浏览器前端优化
    关于ie8下disabled属性:字体颜色问题
    win10永久激活
  • 原文地址:https://www.cnblogs.com/yaodengfeng/p/7760778.html
Copyright © 2011-2022 走看看