LINQ - Set Operators
Distinct去掉重複 Union(合并) Intersect(交集) Except叉集 Concat(串連)
LINQ - Restriction Operators
< > == && ||
LINQ - Query Execution
i++
LINQ - Quantifiers
Any集合中是否有元素滿足某一條件 All集合中所有元素是否都滿足某一條件
Contains集合中是否包含有某一元素 Exists是否存在
LINQ - Projection Operators
dt.AsEnumerable()可用於linq方法 n.Field<int>(column)
LINQ - Partitioning Operators
Take(3)前3個 Skip(4) 跳過前4個 TakeWhile(n => n < 6)不要後面6個 SkipWhile()指定條件跳過
LINQ - Ordering Operators
orderby word orderby word.Length orderby d descending倒敘 words.OrderBy()
words.OrderByDescending() orderby digit.Length, digit
words.OrderBy(a => a.Length).ThenBy(a => a, new CaseInsensitiveComparer());
words.OrderBy(a => a.Length).ThenByDescending(a => a, new CaseInsensitiveComparer());
.Reverse()翻轉
public class CaseInsensitiveComparer : IComparer<string>
{
public int Compare(string x, string y)
{
return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
}
}
LINQ - Miscellaneous Operators
Concat 串連 wordsA.SequenceEqual(wordsB);比較 是否相同
LINQ - Join Operators
join cust in customers on new { sup.City, sup.Country } equals new { cust.City, cust.Country
} into cs
LINQ - Generation Operators
var numbers =from n in Enumerable.Range(100, 50) 產生指定範圍的整數數列
var numbers = Enumerable.Repeat(7, 10); 產生重複的序號
LINQ - Element Operators
.First(); First(s => s[0] == 'o'); FirstOrDefault();
FirstOrDefault(p => p.ProductID == 789); ElementAt(1); 返回索引指定
LINQ - Custom Sequence Operators
public static IEnumerable<S> Combine<S>(this IEnumerable<DataRow> first,
IEnumerable<DataRow> second, System.Func<DataRow, DataRow, S> func)
{
using (IEnumerator<DataRow> e1 = first.GetEnumerator(), e2 =
second.GetEnumerator())
{
while (e1.MoveNext() && e2.MoveNext())
{
yield return func(e1.Current, e2.Current);
}
}
}
var numbersA = testDS.Tables["NumbersA"].AsEnumerable();
var numbersB = testDS.Tables["NumbersB"].AsEnumerable();
int dotProduct = numbersA.Combine(numbersB, (a, b) => a.Field<int>("number")
* b.Field<int>("number")).Sum();
LINQ - Conversion Operators
ToArray(); ToList(); ToDictionary(sr => sr.Name);
numbers.OfType<double>(); 根據指定類型篩選
LINQ - Aggregate Operators
Max Min SUN 要看的
LINQ - Grouping Operators