资源简介
101个linq例子程序.
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.xml.Linq;
namespace GroupingOperators
{
class Program
{
static void Main(string[] args)
{
LinqSamples samples = new LinqSamples();
// Comment or uncomment the method calls below to run or not
samples.DataSetLinq40(); // This sample uses group by to partition a list of numbers by their remainder when divided by 5.
//samples.DataSetLinq41(); // This sample uses group by to partition a list of words by their first letter.
//samples.DataSetLinq42(); // This sample uses group by to partition a list of products by category.
//samples.DataSetLinq43(); // This sample uses group by to partition a list of each customer‘s orders first by year and then by month.
//samples.DataSetLinq44(); // This sample uses GroupBy to partition trimmed elements of an array using a custom comparer that matches words that are anagrams of each other.
//samples.DataSetLinq45(); // This sample uses GroupBy to partition trimmed elements of an array using a custom comparer that matches words that are anagrams of each other and then converts the results to uppercase.
}
private class LinqSamples
{
private DataSet testDS;
public LinqSamples()
{
testDS = TestHelper.CreateTestDataset();
}
[Category(“Grouping Operators“)]
[Description(“This sample uses group by to partition a list of numbers by “ +
“their remainder when divided by 5.“)]
public void DataSetLinq40()
{
var numbers = testDS.Tables[“Numbers“].AsEnumerable();
var numberGroups =
from n in numbers
group n by n.Field(“number“) % 5 into g
select new { Remainder = g.Key Numbers = g };
foreach (var g in numberGroups)
{
Console.WriteLine(“Numbers with a remainder of {0} when divided by 5:“ g.Remainder);
foreach (var n in g.Numbers)
{
Console.WriteLine(n.Field(“number“));
}
}
}
[Category(“Grouping Operators“)]
[Description(“This sample uses group by to partition a list of words by “ +
“their first letter.“)]
public void DataSetLinq41()
{
var words4 = testDS.Tables[“Words4“].AsEnumerable();
var wordGroups =
from w in words4
group w by w.Field(“word“)[0] into g
select new { FirstLetter
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 33225 2014-06-06 12:20 desc
文件 1670 2014-06-06 12:20 desc
文件 0 2014-06-06 12:20 desc
文件 0 2014-06-06 12:20 desc
文件 10457 2014-06-06 12:20 desc
文件 1727 2014-06-06 12:20 desc
文件 71647 2014-06-06 12:20 desc
文件 3369 2014-06-06 12:20 desc
文件 4688 2014-06-06 12:20 license.rtf
文件 139736 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 1670 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 0 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 0 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 10457 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 1727 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 71647 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 3369 2014-06-06 12:20 LINQ - Grouping Operators\desc
文件 3239 2014-06-06 12:20 LINQ - Grouping Operators\license.rtf
文件 893 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators.sln
文件 19456 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators.suo
目录 0 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\
目录 0 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\
目录 0 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\
文件 143963 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\Customers.xm
文件 39424 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\GroupingOperators.exe
文件 42496 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\GroupingOperators.pdb
文件 11600 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\GroupingOperators.vshost.exe
文件 490 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\bin\Debug\GroupingOperators.vshost.exe.manifest
文件 143963 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\Customers.xm
文件 2610 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\GroupingOperators.csproj
目录 0 2014-06-06 12:20 LINQ - Grouping Operators\C#\GroupingOperators\obj\
............此处省略454个文件信息
- 上一篇:高等数学工专
- 下一篇:cesium 卫星轨迹模拟 czml
评论
共有 条评论