补点C#基础_015_数据的初始化和LINQ的使用

1、MartialArtsMaster类。
class MartialArtsMaster
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Menpai { get; set; }
public string Kongfu { get; set; }
public int Level { get; set; }
}

2、
class Program
{
static public List sd;
static void Main(string[] args)
{
//初始化武林高手
var masterList = new List(){
new MartialArtsMaster(){ Id = 1, Name = “黄蓉”, Age = 18, Menpai = “丐帮”, Kongfu = “打狗棒法”, Level = 9 },
new MartialArtsMaster(){ Id = 2, Name = “洪七公”, Age = 70, Menpai = “丐帮”, Kongfu = “打狗棒法”, Level = 10 },
new MartialArtsMaster(){ Id = 3, Name = “郭靖”, Age = 22, Menpai = “丐帮”, Kongfu = “降龙十八掌”,Level = 10 },
new MartialArtsMaster(){ Id = 4, Name = “任我行”, Age = 50, Menpai = “明教”, Kongfu = “葵花宝典”, Level = 1 },
new MartialArtsMaster(){ Id = 5, Name = “东方不败”,Age = 35, Menpai = “明教”, Kongfu = “葵花宝典”, Level = 10 },
new MartialArtsMaster(){ Id = 6, Name = “林平之”, Age = 23, Menpai = “华山”, Kongfu = “葵花宝典”, Level = 7 },
new MartialArtsMaster(){ Id = 7, Name = “岳不群”, Age = 50, Menpai = “华山”, Kongfu = “葵花宝典”, Level = 8 },
new MartialArtsMaster() { Id = 8, Name = “令狐冲”, Age = 23, Menpai = “华山”, Kongfu = “独孤九剑”, Level = 10 },
new MartialArtsMaster() { Id = 9, Name = “梅超风”, Age = 23, Menpai = “桃花岛”, Kongfu = “九阴真经”, Level = 8 },
new MartialArtsMaster() { Id =10, Name = “黄药师”, Age = 23, Menpai = “梅花岛”, Kongfu = “弹指神通”, Level = 10 },
new MartialArtsMaster() { Id = 11, Name = “风清扬”, Age = 23, Menpai = “华山”, Kongfu = “独孤九剑”, Level = 10 }
};
//使用linq查询。
var res = from m in masterList//from后面设置查询的集合
where m.Level > 8//where后面跟上查询的条件。
select m.Name;//表示m的结果结合返回。
foreach (var item in res)
{
Console.WriteLine(item);
}

Console.ReadKey();
}
}

3、结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

unity学院

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值