3个回答
2013-07-14
展开全部
一、LINQ查询符列表
Query Operators
Meaning in Life
from, in
Used to define the backbone for any LINQ expression, which allows you to extract a subset of data from a fitting container.
where
Used to define a restriction for which items to extract from a container.
select
Used to select a sequence from the container.
join, on, equals, into
Performs joins based on specified key. Remember, these “joins” do not need to have anything to do with data in a relational database.
orderby, ascending, descending
Allows the resulting subset to be ordered in ascending or descending order.
group, by
Yields a subset with data grouped by a specified value.
另外还有一些没有操作符号,而是以扩展函数(泛型函数)的方式提供的函数:
用不同方式产生结果集: Reverse<>(), ToArray<>(), ToList<>()
集合操作: Distinct<>(), Union<>(), Intersect<>()
统计函数: Count<>(), Sum<>(), Min<>(), Max<>()
二、使用Enumerable获取Counts
为了使用这些Enumerable扩展函数,一般把LINQ查询表达式用括号括起来,先转换为IEnumerable<T>兼容的对象。
static void GetCount()
{
string[] currentVideoGames = {"Morrowind", "BioShock",
"Half Life 2: Episode 1", "The Darkness",
"Daxter", "System Shock 2"};
// Get count from the query.
int numb = (from g in currentVideoGames
where g.Length > 6
orderby g
select g).Count<string>();
// numb is the value 5.
Console.WriteLine("{0} items honor the LINQ query.", numb);
}
Query Operators
Meaning in Life
from, in
Used to define the backbone for any LINQ expression, which allows you to extract a subset of data from a fitting container.
where
Used to define a restriction for which items to extract from a container.
select
Used to select a sequence from the container.
join, on, equals, into
Performs joins based on specified key. Remember, these “joins” do not need to have anything to do with data in a relational database.
orderby, ascending, descending
Allows the resulting subset to be ordered in ascending or descending order.
group, by
Yields a subset with data grouped by a specified value.
另外还有一些没有操作符号,而是以扩展函数(泛型函数)的方式提供的函数:
用不同方式产生结果集: Reverse<>(), ToArray<>(), ToList<>()
集合操作: Distinct<>(), Union<>(), Intersect<>()
统计函数: Count<>(), Sum<>(), Min<>(), Max<>()
二、使用Enumerable获取Counts
为了使用这些Enumerable扩展函数,一般把LINQ查询表达式用括号括起来,先转换为IEnumerable<T>兼容的对象。
static void GetCount()
{
string[] currentVideoGames = {"Morrowind", "BioShock",
"Half Life 2: Episode 1", "The Darkness",
"Daxter", "System Shock 2"};
// Get count from the query.
int numb = (from g in currentVideoGames
where g.Length > 6
orderby g
select g).Count<string>();
// numb is the value 5.
Console.WriteLine("{0} items honor the LINQ query.", numb);
}
威孚半导体技术
2024-08-19 广告
2024-08-19 广告
威孚(苏州)半导体技术有限公司是一家专注生产、研发、销售晶圆传输设备整机模块(EFEM/SORTER)及核心零部件的高科技半导体公司。公司核心团队均拥有多年半导体行业从业经验,其中技术团队成员博士、硕士学历占比80%以上,依托丰富的软件底层...
点击进入详情页
本回答由威孚半导体技术提供
2013-07-14
展开全部
一个很简单的LINQ查询例子,查询一个int 数组中小于5的数字,并按照大小顺序排列:
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 8, 5, 89, 3, 56, 4, 1, 58 };
var m = from n in arr where n < 5 orderby n select n;
foreach (var n in m)
{
Console.WriteLine(n);
}
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 8, 5, 89, 3, 56, 4, 1, 58 };
var m = from n in arr where n < 5 orderby n select n;
foreach (var n in m)
{
Console.WriteLine(n);
}
Console.ReadLine();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-14
展开全部
会SQL语句的没人用这东西。这都是微软件给不会写sql人用的。因为会写程序的不一定全会写 sql.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询