小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C# Linq

 昵稱10504424 2013-11-18

LINQ- Language Integrated Query 語言集成查詢

LINQ通過對象的方式對數(shù)據(jù)庫進行描述。

LINQ是一種能夠快速對大部分數(shù)據(jù)源進行訪問和數(shù)據(jù)整合的一種技術(shù),使用相同的基本查詢表達式模式類查詢和轉(zhuǎn)換SQL數(shù)據(jù)庫、ADO.NET數(shù)據(jù)集、XML文檔和流已經(jīng).NET集合中的數(shù)據(jù)。

從.NET3.5開始引入LINQ

LINQ to Objects

LINQ to DataSet

LINQ to SQL

LINQ to Entities

LINQ to XML

命名空間

System.Data.Linq 該命名空間包含支持與LINQ to SQL應(yīng)用程序中的關(guān)系數(shù)據(jù)庫進行交互的類

System.Data.Linq.Mapping 該命名空間包含用于生成表示關(guān)系數(shù)據(jù)庫的結(jié)構(gòu)和內(nèi)容的LINQ to SQL對象模型的類

System.Data.Linq.SqlClient 該命名空間包含與SQL Server進行通信的提供程序類,已經(jīng)包含查詢幫助器方法的類

System.Linq 該命名空間提供支持使用語言集成查詢(LINQ)進行查詢的類和接口

System.Linq.Expression 該命名空間包含一些類,接口和枚舉,它們使語言級別的代碼表達式能夠表示為表達式樹形式的對象

System.Xml.Linq 包含LINQ to XML的類,LINQ to XML是內(nèi)存中的XML變成接口

查詢表達式使用form1.cs

復(fù)制代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LinqTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
            //創(chuàng)建查詢
            //查詢結(jié)果的類型是IEnumberable<int>
            var result0 = from num in numbers 
                         where (num % 2) == 0 
                         select num;
            //執(zhí)行查詢結(jié)果
            foreach (int num in result0)
            {
                listBox1.Items.Add(num);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            int[] numbers = new int[7] { 2, 1, 2, 6, 4, 5, 3 };
            var result1 =                       //聲明查詢
                          from num in numbers   //聲明臨時變量num,其值來源于numbers
                          where num>3           //當前值大于3
                          orderby num descending//按照descending方式排序,降序
                          select num;           //將當前項加入到結(jié)果序列中
            foreach (int num in result1)
            {
                listBox1.Items.Add(num);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            int[] numbers = new int[7] { 2, 1, 2, 6, 4, 5, 3 };
            var result2 =                       //聲明查詢
                          from num in numbers   //聲明臨時變量num,其值來源于numbers
                          where num > 3           //當前值大于3
                          orderby num ascending//按照ascending方式排序,升序
                          select string.Format("當前項值為{0}",num);           //將當前項加入到結(jié)果序列中
            foreach (string num in result2)
            {
                listBox1.Items.Add(num);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            int[] numbers = new int[7] { 2, 1, 2, 6, 4, 5, 3 };
            int result3 =                       //聲明查詢
                          (from num in numbers   //聲明臨時變量num,其值來源于numbers
                          where num > 3           //當前值大于3
                          select num).Count();           //將當前項加入到結(jié)果序列中  
            button4.Text += "--" + result3.ToString();
        }
    }
}
復(fù)制代碼

Form1.cs

1

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多