zoukankan      html  css  js  c++  java
  • 数据的初始化和LINQ学习笔记

    LINQ是做数据查询的

      

    {
    public static void Main (string[] args)
    {
    var masterList = new List<MartlalArtsMaster> ()
    {
    new MartlalArtsMaster(){Id = 1,Name = "黄蓉",Age = 18,Menpai = "丐帮",Kongfu = "打狗棒法",Level = 9},
    new MartlalArtsMaster(){Id = 2,Name = "洪七公",Age = 70,Menpai ="丐帮",Kongfu= "打狗棒法",Level =10},
    new MartlalArtsMaster(){Id = 3,Name = "郭靖",Age = 26,Menpai = "丐帮",Kongfu = "降龙十八掌",Level = 10},
    new MartlalArtsMaster(){Id = 4,Name = "任我行",Age = 50,Menpai = "明教",Kongfu = "葵花宝典",Level = 1},
    new MartlalArtsMaster(){Id = 5,Name = "东方不败",Age = 35,Menpai = "明教",Kongfu = "葵花宝典",Level = 10},
    new MartlalArtsMaster(){Id = 6,Name = "林平之",Age = 23,Menpai = "华山",Kongfu = "葵花宝典",Level = 7},
    new MartlalArtsMaster(){Id = 7,Name = "岳不群",Age = 50,Menpai = "华山",Kongfu = "葵花宝典",Level = 8},
    new MartlalArtsMaster(){Id = 8,Name = "令狐冲",Age = 30,Menpai = "华山",Kongfu = "独孤九剑",Level = 10},
    new MartlalArtsMaster(){Id = 9,Name = "梅超风",Age = 23,Menpai = "桃花岛",Kongfu = "九阳真经",Level = 8},
    new MartlalArtsMaster(){Id = 10,Name = "黄药师",Age = 23,Menpai = "梅花岛",Kongfu = "弹指神功",Level = 10},
    new MartlalArtsMaster(){Id = 11,Name = "风清扬",Age = 23,Menpai = "华山",Kongfu = "独孤九剑",Level = 10}
    };

    var kongfu = new List<Kongfu> ()
    {
    new Kongfu(){Id = 1,Name = "打狗棒法",Power = 90},
    new Kongfu(){Id = 2,Name = "降龙十八掌",Power = 95},
    new Kongfu(){Id = 3,Name = "葵花宝典",Power = 100},
    new Kongfu(){Id = 4,Name = "独孤九剑",Power = 100},
    new Kongfu(){Id = 5,Name = "九阴真经",Power = 100},
    new Kongfu(){Id = 6,Name = "弹指神功",Power = 100}
    };

    //查询所有级别大于8的
    // var res = new List<MartlalArtsMaster>();
    // foreach (var temp in masterList)
    // {
    // if (temp.Level>8)
    // {
    // res.Add (temp);
    //
    // }
    //// }
    // var res = from m in masterList //从masterLIst中去观察元素名称叫做m的集合res
    // where m.Level > 8&&m.Menpai=="丐帮" //表示选择的限制条件
    // select m; //表示条件的返回值为m
    var res = masterList.Where(m=>m.Level>8&&m.Menpai=="丐帮"); //正则表达式优化扩展以后的写法

    foreach (var temp in res)
    {
    Console.WriteLine (temp);
    }

    Console.ReadKey ();
    }
    }

  • 相关阅读:
    用css3实现一个带缺口的圆圈(图)
    markdown语法练习
    Android SDK + Appium 环境搭建
    Python + Robot Framework 环境搭建
    javascript动画效果之透明度
    javascript动画效果之匀速运动
    JS中offsetTop、clientTop、scrollTop、offsetTop各属性介绍(转载)
    javascript焦点图自动播放
    js中的随机数
    javascript焦点图(根据图片下方的小框自动播放)
  • 原文地址:https://www.cnblogs.com/ylllove/p/6765034.html
Copyright © 2011-2022 走看看