linq是語言集成查詢。
linq to object? ?:面向?qū)ο蟮牟樵儭?/p>
linq to xml:針對(duì)xml查詢。
linq to ADO.NET:主要負(fù)責(zé)對(duì)數(shù)據(jù)庫的查詢撞牢。
linq to Datset
linq to SQL
LINQ TO ENTITY
代碼分析:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
? ? public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }
? ? ? ? private void btntiyan_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? int[] arr = { 123, 12, 3, 13, 46, 47, 56, 345 };
? ? ? ? ? ? //獲取大于50的數(shù)
? ? ? ? ? ? //var query = from a in arr
? ? ? ? ? ? //? ? ? ? ? ? where a > 50
? ? ? ? ? ? //? ? ? ? ? ? select arr;
? ? ? ? ? ? //foreach (var item in query)
? ? ? ? ? ? //{
? ? ? ? ? ? //? ? Console.WriteLine();
? ? ? ? ? ? //}
? ? ? ? ? ? IEnumerable ie = arr.Select(p => p).Where(p => p > 50);
? ? ? ? ? ? IEnumerator result = ie.GetEnumerator();
? ? ? ? ? ? while (result.MoveNext())
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine(result.Current);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? private void btnkuozhan_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? //拓展方法
? ? ? ? ? ? string s = "asdad";
? ? ? ? ? ? Console.WriteLine(s.ToUpper());
? ? ? ? ? ? Console.WriteLine(s.ToLower());
? ? ? ? ? ? Console.WriteLine(s.ToPascal());
? ? ? ? ? ? Console.WriteLine(s.ToPascal(2));
? ? ? ? ? ? //拓展方法,對(duì)現(xiàn)有的類提供額外的方法以增強(qiáng)
? ? ? ? ? ? //擴(kuò)展方法是一種特殊的靜態(tài)方法
? ? ? ? ? ? //擴(kuò)展方法必須在靜態(tài)類中定義
? ? ? ? ? ? //除非必要不要濫用擴(kuò)展方法
? ? ? ? }
? ? }
? ? //拓展類,只要是靜態(tài)就可以
? ? public static class ExtraClass
? ? {
? ? ? ? public static string ToPascal(this string s)
? ? ? ? {
? ? ? ? ? ? return s.Substring(0, 1).ToUpper()+s.Substring(1).ToLower();
? ? ? ? }
? ? ? ? public static string ToPascal(this string s,int len)
? ? ? ? {
? ? ? ? ? ? return s.Substring(0, 1).ToUpper() + s.Substring(1,len).ToLower();
? ? ? ? }
? ? }
}
輸出結(jié)果:
總結(jié):
linq中方法絕大多數(shù)是靜態(tài)的屋彪。
linq中方法優(yōu)先級(jí)低所宰、