1
class
StartWithLINQ
{
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
static int[] numbers = new Int32[7]
{ 0, 1, 2, 3, 4, 5, 6 };
3![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public StartWithLINQ()
{
4
var numberQuery =
5
from x in numbers
6
where (x % 2) == 0
7
select x;
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
foreach (int item in numberQuery)
{
9
Console.WriteLine("x = {0}", item);
10
}
11
}
12
}
首先创建了一个数组,包含7个成员,接着在从这个序列中筛选出所有能被2整除的元素并输出。OK,初次使用的时候还是有些不太适应这个语法,感觉怪怪的。想象一下,如果我们不用LINQ,我们的做法可能会少有不同,我们会自己去Foreach这个数组,判断后输出。代码量和现在的也没有什么太大差异。
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
下面来看看F#的同样功能实现吧,呵呵!
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
以前看到关于函数式编程的资料,说如何的提高开发效率降低代码量,我还持怀疑态度,哎!不服不行啊。F#支持安全的多线程操作和并发多核心处理器优势,也许我们在一些关键组件上可以使用这些技术来提高我们的生产效率和软件的稳定性。目前来看,F#的应用领域可能更多的在数据密集型和逻辑复杂的业务处理,在服务端的优势在于线程安全和并发优势。(据说,F#的核心开发Leader是为.Net 2.0设计泛型的)
以上是本人的拙见,还希望能和大家共同学习探讨。