回答
- 幾乎任何與收藏是LINQ容易對象。我發現比LINQ to SQL更有用。
- 我已經變得非常喜歡Marc Gravell和我開發的框架,名爲Push LINQ(目前是MiscUtil的一部分,但最終可能轉到MoreLINQ)。這對計算大型流數據集上的聚合非常有用,例如巨大的日誌文件
- LINQ to XML是我用過的最好的XML API,它與LINQ to Objects很好地集成在一起。
- 並行LINQ是並行擴展框架的一個非常不錯的一部分 - 它肯定更容易並行任務的地方適當(雖然它可以去hideously wrong如果你不小心)
我喜歡這個網站blog.functionalfun.net這個確切的目的:LINQ的實用(而且不太實用,更有趣)。最終,他所涵蓋的幾乎所有內容都可以應用到現實生活中,但他開始在博客上寫更多的「實用LINQ」主題,用於他在業務邏輯代碼中使用的有趣內容。
感謝堵我的博客,安東尼。我想我會爲此投票! – 2009-04-23 14:01:54
Bart De Smet的博客有一些LINQ的巧妙用法,如Who ever said LINQ predicates need to be Boolean-valued?。
微軟的羅伯特·謝爾頓是不夠冷靜,列出a few LINQ implementations我們:
爲月7,2008年:
- LINQ到Amazon
- LINQ到Active Directory
- LINQ到可綁定來源(SyncLINQ)
- 通過C-項目的LINQ
- LINQ到CRM
- LINQ到地球語言集成查詢地理空間數據
- LINQ到Excel
- LINQ表達式(MetaLinq)
- LINQ擴展(工具包構建LINQ提供程序)
- LINQ到Flickr
- LINQ以谷歌
- LINQ到索引(LINQ和I40)
- LINQ到的IQueryable(馬特·沃倫提供商)
- LINQ到JSON
- 的LINQ to NHibernate的
- LINQ到JavaScript的
- LINQ到LDAP
- LINQ到LLBLGEN臨
- LINQ到Lucene的
- LINQ到Metaweb(遊離鹼)
- LINQ到MySQL ,Oracle和PostgreSql(DbLinq)
- LINQ到NCover
- LINQ到Opf3
- LINQ到並行(PLINQ)
- LINQ到RDF文件
- LINQ到SharePoint
- LINQ到SimpleDB的
- LINQ到流
- LINQ到WebQueries
- LINQ到WMI
- LINQ到XtraGrid
如何添加鏈接到這些?可以作爲一個很好的LINQ to x字典工作... – Svish 2009-04-24 07:19:04
您也應該檢查出Bindable LINQ,從CodePlex上的網站:
「可綁定LINQ是一組添加數據綁定和 更改傳播能力 標準LINQ查詢擴展 到LINQ的
和傳播變化一樣, Bindable LINQ可以在運行時分析您的查詢 並檢測您的查詢的任何依賴關係 。如果這些依賴關係爲 提供活動訂閱, Bindable LINQ將自動 監控他們的變化。 「
下面是從網站的一個例子:
拿這個查詢,例如:
contactsListBox.ItemsSource = from c in customers
where c.Name.StartsWith(textBox1.Text)
select c;
可綁定LINQ將檢測 查詢依賴文本屬性 TextBox對象,textBox1。由於 TextBox是一個WPF控件,B indable LINQ知道訂閱控件上的 TextChanged事件。
最終結果是,作爲用戶 類型,查詢中的項目是 重新評估,並且更改顯示在 屏幕上。無需額外的代碼 來處理事件。
Linq to Excel使從Excel電子表格中檢索數據變得輕而易舉。它負責創建OLEDB連接和sql語句。你所要做的就是告訴它電子表格的文件路徑並創建linq語句。
我用LINQ解決了一些C#語句中的Project Euler。 (請注意,陳述與行不一樣)
請注意:邪惡的討厭技巧。
//Euler 1
//Add all the natural numbers below one thousand that are multiples of 3 or 5.
Enumerable.Range(0, 1000).Where(i => i % 5 == 0 || i % 3 == 0).Sum()
//Euler 2
//Find the sum of all the even-valued terms in the sequence which do not exceed four million
//Enumerable.Repeat(new List<long>(1024){ 1, 1 }, 1).First(fib => Enumerable.Range(0, int.MaxValue).TakeWhile(i => fib.Last() <= 4000000)
.Aggregate(true, (u1, u2) => { fib.Add(fib.Last() + fib[fib.Count - 2]); return true; })).Where(n => n % 2 == 0).Sum()
//Euler 3 (>32bit)
//What is the largest prime factor of the number 600851475143?
Enumerable.Range(2, Int32.MaxValue - 2).Where(n => 600851475143 % n == 0 && Enumerable.Range(2, n/2 - 1).All(f => n % f > 0)).Max()
//Euler 4
//Find the largest palindrome made from the product of two 3-digit numbers.
Enumerable.Range(100, 900).SelectMany(x => Enumerable.Range(100, 900).Select(y => x * y))
.Where(n => { var s = n.ToString(); return s.SequenceEqual(s.Reverse()); }).Max()
//Euler 5 (>32bit)
//What is the smallest number divisible by each of the numbers 1 to 20?
Enumerable.Range(20, Int32.MaxValue - 21).Where(n => Enumerable.Range(1, 20).All(i => n % i == 0)).First()
//Euler 6
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Math.Pow(Enumerable.Range(1, 100).Sum(), 2) - Enumerable.Range(1, 100).Select(i => i * i).Sum()
//Euler 7
//Find the 10001st prime.
Enumerable.Range(2, Int32.MaxValue - 1).Where(n => Enumerable.Range(2, n/2 - 1).All(f => n % f > 0)).Skip(10000).First()
//Euler 8
//Discover the largest product of five consecutive digits in the 1000-digit number.
Enumerable.Range(0, 995).Select(i => "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
.Substring(i,5).Select(c => c - '0').Aggregate(1, (x, y) => x * y)).Max()
//Euler 10
//Find the sum of all the primes below two million.
Enumerable.Range(2, 2000000).Where(n => Enumerable.Range(2, n/2 - 1).All(f => n % f > 0)).Select(x => (long)x).Sum()
Enumerable.Range(0, 168).Aggregate(Enumerable.Range(2, 2000000).Select(x => (long)x).ToList(), (result, index) => { result.RemoveAll(i => i > result[index] && i % result[index] == 0); return result; }).Sum()
Enumerable.Repeat(Enumerable.Range(2, 2000000).Select(x => (long)x).ToList(), 1).SelectMany(list => Enumerable.Range(0, Int32.MaxValue).Select(i => new { List = list, Index = i }))
.TakeWhile((g, i) => g.List[g.Index] * g.List[g.Index] <= 2000000 || i.Dump("Rounds") != i).Aggregate((List<long>) null, (result, g) => { g.List.RemoveAll(i => i > g.List[g.Index] && i % g.List[g.Index] == 0); return g.List; }).Sum()
Enumerable.Repeat(Enumerable.Range(2, 2000000).Select(x => (long)x).ToList(), 1).First(list => Enumerable.Range(0, Int32.MaxValue)
.TakeWhile(i => list[i] * list[i] <= 2000000 || i.Dump("Rounds")!=i).Aggregate(0, (count, i) => count + list.RemoveAll(j => j > list[i] && j % list[i] == 0)) != null).Sum()
//Euler 14
Enumerable.Range(1, 1000000).Select(s => Enumerable.Repeat(new List<long>(32) { s }, 1).First(list => Enumerable.Range(0, Int32.MaxValue).TakeWhile(i => list.Last() > 1)
.Aggregate(0, (index, unused) => { list.Add(list.Last() % 2 == 0 ? list.Last()/2 : 3 * list.Last() + 1); return 1; }) == 1 || true))
.Aggregate(new List<long>(), (list, result) => list.Count <= result.Count ? result : list)
//Euler 19
//How many Sundays fell on the first of the month during the twentieth century?
Enumerable.Range(1901,100).SelectMany(y => Enumerable.Range(1,12).Select(m => new DateTime(y, m, 1))).Where(d => d.DayOfWeek == DayOfWeek.Sunday)
//Euler 21
//Evaluate the sum of all the amicable numbers under 10000.
Enumerable.Repeat(new Func<int, int>(n => Enumerable.Range(1, n/2).Where(d => n % d == 0).Sum()), 1)
.Select(D => Enumerable.Range(1, 10000).Where(a => a == D(D(a)) && a != D(a)).Sum())
//Euler 34
//Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Enumerable.Range(3, 40600).Where(n => n == n.ToString().Select(d => Enumerable.Range(1, d - '0').Aggregate(1, (r, i) => r * i)).Sum()).Sum()
//Euler 40
Enumerable.Repeat(new StringBuilder(), 1)
.Where(result => Enumerable.Range(0, Int32.MaxValue)
.TakeWhile(i => result.Length <= 1000000)
.Aggregate(result, (unused, index) => result.Append(index)) != null)
.Select(result => Enumerable.Range(1, 6).Select(i => result[(int)Math.Pow(10, i)] - '0')).First().Aggregate(1, (x, y) => x * y)
其他LINQ的俏皮話:
//Primes (Ineffecient)
Enumerable.Range(2, 1000000).Where(n => Enumerable.Range(2, n/2 - 1).All(f => n % f > 0)).Count()
//Sieve of Eratosthenes
Enumerable.Range(0, 168)
.Aggregate(Enumerable.Range(2, 1000000).ToList(), (result, index) => {
result.RemoveAll(i => i > result[index] && i % result[index] == 0);
return result;
}).Count
//Prime Factors
Enumerable.Range(2,13195/2)
.Where(n => 13195 % n == 0
&& Enumerable.Range(2, n/2 - 1).All(f => n % f > 0))
//Fibonacci
Enumerable.Repeat(new List<long>(32){ 1, 1 }, 1)
.First(fib => Enumerable.Range(0, 32).Aggregate(true, (u1, u2) => {
fib.Add(fib.Last() + fib[fib.Count - 2]);
return true;
}))
- 1. 巧妙地迭代
- 2. 巧妙的方法來查找行
- 3. 巧妙的方式? - Python的
- 4. 什麼是3D monte carlo集成的巧妙邊界框?
- 5. 什麼是分層面板的巧妙設計?
- 6. 巧妙比較「喜歡」
- 7. 巧妙使用鏈接器腳本?
- 8. 有沒有一種巧妙的方法來處理這個空對象引用?
- 9. 有沒有一種巧妙的方法來彌補MySQL的更新?
- 10. 有誰知道重複使用身份值的巧妙方法嗎?
- 11. 如何使用LINQ和Lambda巧妙地從XDocument中刪除節點?
- 12. 巧妙地擴展bootstrap datepicker函數
- 13. jQuery:巧妙消化快速事件
- 14. Numpy:如何巧妙地填充數組?
- 15. 針對當前腳本的巧妙解決方法?
- 16. 在Zend驗證get參數的巧妙方法
- 17. 提交後添加文件到變更集的巧妙方法?
- 18. 調試javascript有什麼好的技巧?
- 19. 巧妙的方法有條件測試是否添加類HAML模板
- 20. ko.dependentObservable這個方法如何巧妙地理解依賴關係?
- 21. 軌道中的巧妙的通用形式部分
- 22. 使用與波本威士忌巧妙的嵌套斷點
- 23. 如何巧妙地重寫曾經使用XSLT的python腳本?
- 24. 如何巧妙地通知用戶他的輸入已收到
- 25. 使用foreach在Java中迭代並行數組的巧妙方法
- 26. 節點js使用Mongo和Redis巧妙地使用
- 27. 有沒有一種巧妙的方法使用Django ORM獲取上一個/下一個項目?
- 28. 有沒有一種巧妙的方式來顯示iPhone OSStatus錯誤值?
- 29. 使用一些引擎開始遊戲開發是否巧妙?
- 30. 在webpack中巧妙地導入js lib,使用css
直到現在還沒有閱讀推LINQ解釋,以後可能會用它來查看日誌文件:) – 2009-04-22 21:26:05