zoukankan      html  css  js  c++  java
  • LinQ

    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、

  • 相关阅读:
    CFS 调度器
    RCU
    linux cfs 负载均衡
    wait_event_interruptible_timeout
    算法(13)Contiguous Array
    算法(12)Pascal's Triangle II
    算法(12)Best Time to Buy and Sell Stock II
    算法(11)Find All Duplicates in an Array
    算法(10)Subarray Sum Equals K
    算法(9)Find the Duplicate Number
  • 原文地址:https://www.cnblogs.com/javier520/p/10803895.html
Copyright © 2011-2022 走看看