LinQ

博客展示了Linq的简单查询示例,包括对整数数组和字符串数组的查询。强调Linq查询只是定义规则,可多次执行,where条件能有多个。通过代码示例展示了如何筛选出符合条件的数据并输出结果。

1、简单查询int[] nums = { 1, 2, 5, -4, -9, 78, -54, 98 };

需要注意的是:

  Linq查询只是定义了查询规则,执行可以多次进行,where条件可以有多个(以“&&”连接或者直接下行再写where)

//LinQ查询都是以From开始,以Select或者group结束
//LinQ的过程:
  1、创建查询
  2、执行查询

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace demo1
{
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, 2, 5, -4, -9, 78, -54, 98 };

//创建查询
var dictionaries = from n in nums
where n > 0&&n<10
select n;
StringBuilder sb = new StringBuilder();

//执行查询
foreach (var item in dictionaries)
{
sb = sb.AppendFormat("{0},",item);
}
Console.WriteLine(sb);


string[] webUrl = { "www.A-com.com", "www.A-org.org", "www.A-cn.cn", "www.B-com.com", "www.C-com.com",
"www.B-org.org" };
var comUrl=from url in webUrl
where url.EndsWith(".com")
select url;
StringBuilder sbUrl = new StringBuilder();
foreach (var item in comUrl)
{
sbUrl = sbUrl.AppendFormat("{0},",item);
}
Console.WriteLine(sbUrl);
Console.Read();
}
}
}

 

结果:

2、

转载于:https://www.cnblogs.com/javier520/p/10803895.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值