Linq101-Conversion Operators
using System;
using System.Linq; namespace Linq101
{
class Conversion
{
/// <summary>
/// This sample uses ToArray to immediately evaluate a sequence into an array.
/// </summary>
public void Linq54()
{
double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 }; //var doublesArray = doubles.OrderByDescending(d => d).ToArray();
var sortedDoubles = from d in doubles
orderby d descending
select d;
var doublesArray = sortedDoubles.ToArray(); Console.WriteLine("Every other double from highest to lowest:");
for (int d = ; d < doublesArray.Length; d += )
{
Console.WriteLine(doublesArray[d]);
}
} /// <summary>
/// This sample uses ToList to immediately evaluate a sequence into a List<T>.
/// </summary>
public void Linq55()
{
string[] words = { "cherry", "apple", "blueberry" }; //var wordList = words.OrderBy(w => w).ToList();
var sortedWords =
from w in words
orderby w
select w;
var wordList = sortedWords.ToList(); Console.WriteLine("The sorted word list:");
foreach (var w in wordList)
{
Console.WriteLine(w);
}
} /// <summary>
/// This sample uses ToDictionary to immediately evaluate a sequence and a related key expression into a dictionary.
/// </summary>
public void Linq56()
{
var scoreRecords = new[] { new {Name = "Alice", Score = },
new {Name = "Bob" , Score = },
new {Name = "Cathy", Score = }
}; var scoreRecordsDict = scoreRecords.ToDictionary(s => s.Name); Console.WriteLine("Bob' Score: {0}", scoreRecordsDict["Bob"].Score);
} /// <summary>
/// This sample uses OfType to return only the elements of the array that are of type double.
/// </summary>
public void Linq57()
{
object[] numbers = { null, 1.0, "two", , "four", , "six", 7.0 }; var doubles = numbers.OfType<double>(); Console.WriteLine("Numbers stored as doubles:");
foreach (var d in doubles)
{
Console.WriteLine(d);
}
}
}
}
Linq101-Conversion Operators的更多相关文章
- Conversion Operators in OpenCascade
Conversion Operators in OpenCascade eryar@163.com Abstract. C++ lets us redefine the meaning of the ...
- Advanced C++ | Conversion Operators
In C++, the programmer abstracts real world objects using classes as concrete types. Sometimes it is ...
- LINQ 学习路程 -- 查询操作 Conversion Operators
Method Description AsEnumerable Returns the input sequence as IEnumerable<t> AsQueryable Conve ...
- 101个LINQ示例,包含几乎全部操作
Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...
- [c++] Operator overloading
c++的操蛋属性:自己为一档,空一档,其他随意. UB_stack a; UB_stack b = a; // copy auto c = a; auto d {a}; // (or auto d = ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- CLR via C# 3rd - 08 - Methods
Kinds of methods Constructors Type constructors Overload operators Type con ...
- CLR via C# 3rd - 06 - Type and Member Basics
1. Different Kinds of Type Members A type can define zero or more of the following kinds of ...
- C++的隐式类型转换与转换操作符
C++标准允许隐式类型转换,即对特定的类,在特定条件下,某些参数或变量将隐形转换成类对象(创建临时对象).如果这种转换代价很大(调用类的构造函数),隐式转换将影响性能.隐式转换的发生条件:函数调用中, ...
- C#复习④
C#复习④ 2016年6月16日 12:37 Main Classes and Structs 类和结构体 1.Contents of Classes 字段,常量,方法,构造函数,析构函数: 特性,事 ...
随机推荐
- [BZOJ 1072] [SCOI2007] 排列perm 【状压DP】
题目链接:BZOJ 1072 这道题使用 C++ STL 的 next_permutation() 函数直接暴力就可以AC .(使用 Set 判断是否重复) 代码如下: #include <io ...
- VBA读取word中的内容到Excel中
原文:VBA读取word中的内容到Excel中 Public Sub Duqu() Dim myFile As String Dim docApp As Word.Applicati ...
- 对于唯一索引使用唯一条件搜索, InnoDB 只锁定找到的index record,不是它之前的区间
| test100 | CREATE TABLE `test100` ( `sn` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增编号', `phoneNo` ...
- UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]
题意: 求矩形覆盖K次以上的面积 分析: k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次 // File Name: 11983.cpp // Author: ...
- Android USB安全调试
Android 4.2.2 引入了USB安全调试方面的内容,当启用安全调试的时候,只有被用户认证过的主机才可以通过Android SDK自带的ADB工具经由USB连接来访问设备的内部构件. 下面以an ...
- PostgreSQL安装详细步骤(windows)
原文地址:http://blog.chinaunix.net/uid-354915-id-3498734.html PostgreSQL安装:一.windows下安装过程安装介质:postgresql ...
- selenium grid 搭建
hub端 Step1: 下载 selenium-server-standalone-x.xx.x.jar我下载的是:selenium-server-standalone-2.44.0.jar下载地址: ...
- hdu 3698 Let the light guide us(线段树优化&简单DP)
Let the light guide us Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/O ...
- linux 挂载ISO
首先,将作为源的iso的挂载到系统上. 代码如下: mount -o loop /xxx/xxx.iso /mnt/iso/ 其中/mnt/iso是事先在本地建立的文件夹. 然后将文件iso.repo ...
- Android eclipse下数据开源框架GreenDao的配置
1.前言 ORM(Object-RelationMapping,对象关系映射),是一种为了解决面向对象与数据库存在的互一匹配的现象的技术,通过描述对象和关系数据库之间的映射,将程序中的对象自动持久化到 ...