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的更多相关文章

  1. Conversion Operators in OpenCascade

    Conversion Operators in OpenCascade eryar@163.com Abstract. C++ lets us redefine the meaning of the ...

  2. Advanced C++ | Conversion Operators

    In C++, the programmer abstracts real world objects using classes as concrete types. Sometimes it is ...

  3. LINQ 学习路程 -- 查询操作 Conversion Operators

    Method Description AsEnumerable Returns the input sequence as IEnumerable<t> AsQueryable Conve ...

  4. 101个LINQ示例,包含几乎全部操作

    Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...

  5. [c++] Operator overloading

    c++的操蛋属性:自己为一档,空一档,其他随意. UB_stack a; UB_stack b = a; // copy auto c = a; auto d {a}; // (or auto d = ...

  6. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  7. CLR via C# 3rd - 08 - Methods

       Kinds of methods        Constructors      Type constructors      Overload operators      Type con ...

  8. 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 ...

  9. C++的隐式类型转换与转换操作符

    C++标准允许隐式类型转换,即对特定的类,在特定条件下,某些参数或变量将隐形转换成类对象(创建临时对象).如果这种转换代价很大(调用类的构造函数),隐式转换将影响性能.隐式转换的发生条件:函数调用中, ...

  10. C#复习④

    C#复习④ 2016年6月16日 12:37 Main Classes and Structs 类和结构体 1.Contents of Classes 字段,常量,方法,构造函数,析构函数: 特性,事 ...

随机推荐

  1. 『安全科普』WEB安全之渗透测试流程

    熟悉渗透流程,攻击会像摆积木一样简单! 0x 01:信息收集 收集网站信息对渗透测试非常重要,收集到的信息往往会让你在渗透中获得意外惊喜. 1. 网站结构 可以使用扫描工具扫描目录,主要扫出网站管理员 ...

  2. MFC 如何改变对话框按钮上的文字

    原文地址:http://blog.163.com/wenxianliang08@126/blog/static/8358326320110300643282/ 什么是标记菜单  如何标记菜单   如何 ...

  3. tomcat源码阅读

    1      工具准备 需要SVN.Maven.JDK.Eclipse.Eclipse M2插件 2      下载源码及发布包 源码在这里:http://svn.apache.org/repos/a ...

  4. 开始LXC,DOCKER,VAGRANT,COREOS之旅

    很有兴趣哟. 有人说会重构互联基质,可能言重. 但,无疑在未来几年内,DOCKER和COREOS这样的更新布置模式会流行.

  5. Timus1132(二次剩余方程求解)

    题目:http://acm.timus.ru/problem.aspx?space=1&num=1132 题意:就是给出方程,p为素数,求在区间内的解. 这个思路很简单,详见:http://a ...

  6. bootchart--检测linux启动性能的软件

    bootchart--检测linux启动性能的软件 摘自http://www-128.ibm.com/developerworks/library/l-boot-faster/index.html?c ...

  7. XFS文件系统功能解析

    XFS文件系统是作为一个日志文件系统开发,采用B-树平衡树算法来尽快地分配数据.主要的设计目的之一是支持大型文件和大型文件系统.当前,能够支持的最大文件大小是2艾字节,最大文件系统大小为8艾字节. X ...

  8. Naive and Silly Muggles (计算几何)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  9. sed删除文本第一个匹配行

    源文本如下,要求删除第一个为happy-123456的行. ----------------------------- aaaaaaa happy- bbbbbb asdasawe happy- ds ...

  10. Unix/Linux运维首选工具Xmanager Enterprise 3.0的使用教程

    管理Uinx和Linux服务器的兄弟们应该很熟悉Xmanager,一个窗口可以同时控制上百台Linux和Unix服务器,功能非常强大!^_^请看: manager是一个简单易用的高性能的运行在Wind ...