一段关于linq的代码
来源:互联网 发布:app开放端口什么意思 编辑:程序博客网 时间:2024/05/17 00:54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace linq2
{
class Program
{
class cl
{
public string id { get; set; }
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
public string d { get; set; }
public override string ToString()
{
return "id: " + id + " a: " + a + " b: " + b + " c: " + c + " d: " + d;
}
}
static void Main(string[] args)
{
List<cl>cls=new List<cl>{
new cl{id="a",a="1",b="one",c="aa",d="d"},
new cl{id="b",a="2",b="two",c="bb",d="d"},
new cl{id="c",a="3",b="three",c="cc",d="d3"},
new cl{id="d",a="4",b="four",c="dd",d="d"},
new cl{id="e",a="5",b="five",c="ee",d="d5"},
new cl{id="f",a="6",b="six",c="ff",d="d"},
new cl{id="g",a="7",b="seven",c="gg",d="d7"},
new cl{id="h",a="8",b="eight",c="hh",d="d"}};
var qu=from c in cls where c.d=="d"select c;
foreach (cl cll in qu)
{
Console.WriteLine(cll);
}
Console.WriteLine();
var q = from cc in cls orderby cc.b select cc;
foreach (cl i in q)
{
Console.WriteLine(i);
}
Console.WriteLine();
var it=cls.OrderBy(c=>c.a).ThenBy(c=>c.b).ThenBy(c=>c.c).ThenBy(c=>c.d).Select(c=>c);
foreach(cl ite in it)
{
Console.WriteLine(ite);
}
Console.WriteLine();
var i1 = from c in cls group c by c.b into bg select bg;
foreach (var i2 in i1)
{
Console.WriteLine(i2);
}
bool anyd = cls.Any(c => c.d == "d");
bool alld = cls.All(c => c.d == "d");
Console.WriteLine("{0} {1}", anyd, alld);
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace linq2
{
class Program
{
class cl
{
public string id { get; set; }
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
public string d { get; set; }
public override string ToString()
{
return "id: " + id + " a: " + a + " b: " + b + " c: " + c + " d: " + d;
}
}
static void Main(string[] args)
{
List<cl>cls=new List<cl>{
new cl{id="a",a="1",b="one",c="aa",d="d"},
new cl{id="b",a="2",b="two",c="bb",d="d"},
new cl{id="c",a="3",b="three",c="cc",d="d3"},
new cl{id="d",a="4",b="four",c="dd",d="d"},
new cl{id="e",a="5",b="five",c="ee",d="d5"},
new cl{id="f",a="6",b="six",c="ff",d="d"},
new cl{id="g",a="7",b="seven",c="gg",d="d7"},
new cl{id="h",a="8",b="eight",c="hh",d="d"}};
var qu=from c in cls where c.d=="d"select c;
foreach (cl cll in qu)
{
Console.WriteLine(cll);
}
Console.WriteLine();
var q = from cc in cls orderby cc.b select cc;
foreach (cl i in q)
{
Console.WriteLine(i);
}
Console.WriteLine();
var it=cls.OrderBy(c=>c.a).ThenBy(c=>c.b).ThenBy(c=>c.c).ThenBy(c=>c.d).Select(c=>c);
foreach(cl ite in it)
{
Console.WriteLine(ite);
}
Console.WriteLine();
var i1 = from c in cls group c by c.b into bg select bg;
foreach (var i2 in i1)
{
Console.WriteLine(i2);
}
bool anyd = cls.Any(c => c.d == "d");
bool alld = cls.All(c => c.d == "d");
Console.WriteLine("{0} {1}", anyd, alld);
Console.ReadKey();
}
}
}
0 0
- 一段关于linq的代码
- 关于回文的一段代码
- 关于Const的一段代码
- 一段关于webGL的代码
- 关于kdtree的一段代码
- 一段关于tableViewController的代码
- 关于数组的一段代码
- 关于string的一段代码
- 一段关于静态的代码
- 关于线程池的一段代码
- opencv关于摄像机标定的一段代码
- 关于bitset 的一段代码--初级
- 关于线程信号量的一段小代码
- 关于+—~有意思的一段C代码
- teechart 上的 关于Custom axes的一段代码
- 一段关于带阴影的UIView切圆角的代码
- 关于com解释的一段代码,你懂的
- 一段代码的欣赏--------关于super.xx()方法的使用
- 如何防止哲学家就餐问题而引起的死锁
- Servlet、Biz、Dao和Vo关系描述
- solaris10使用projadd进行资源限制的添加(seminfo_*)
- unity3d 模拟人体皮肤
- linux下装法firefox64位flash插件
- 一段关于linq的代码
- 第十六周 项目四--为动态数组扩容
- 这是一个问题,mysql数据库的id生成方式GeneratedValue不设值报错,求大神解答
- Princeton Algorithms: Part 2 [week 5: Tries]
- makefile入门的一个简单例子
- 鸟哥的Linux私房菜笔记6------11章认识和学习bash
- python进阶——利用网页爬虫写天气预报采集器
- 第十六周项目2.3求字符串的长度
- C标准函数库