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. Recovery和Charger模式下屏幕旋转180度[转]

    如何让Recovery (系统固件升级),charger(关机充电动画)时屏幕旋转180度 解决方法: 1.在bootable\recovery\minui\Graphics.c 文件找到gr_fli ...

  2. linux中bin和xbin下可执行程序的区别

    /bin下的都是Linux最基础的,所有用户都可以使用的外部命令 /sbin下的都是只有超级用户root才能使用的.管理Linux系统的外部命令 /usr/bin以及/usr/local/bin下的都 ...

  3. Can deep learning help you find the perfect girl?

    Can deep learning help you find the perfect girl? One of the first things I did when I moved to Mont ...

  4. [原创]leet code - path sum

    ;            ;                ;                            }        }        ;            }};

  5. stat~~~访问文件状态的利器

    Name stat, fstat, lstat - get file status Synopsis #include <sys/types.h>#include <sys/stat ...

  6. 2015 CCC - 02 找不匹配

    照例传送门CNUOJ - 0385:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=355 题目分析:首先感谢”数据结构与算法“群群友 ...

  7. hdu-4612-Warm up(边双连通分量--有重边)

    题意:有N 个点,M条边,加一条边,求割边最少.(有重边) 分析:先求双连通分量,缩点形成一个生成树,然后求这个的直径,割边-直径即是答案 因为有的图上可能有重边,这样不好处理.我们记录每条边的标号( ...

  8. Android数据加密解密

    最近项目在维护过程中,估计这一周都会没有什么事情做了.于是开始打量自己做完的这个项目,项目在展示方面乏善可陈,然后仔细的想了想,这个项目的亮点无非就在数据加密和解密这一块了.因为是银行的项目,所以对数 ...

  9. 安装ucenter 步骤详解及supesite 安装详解

    最近弄一个 php 的cms  ,花了周六日时间研究了一下,这里记录一下,首先在网页上下载ucenter(分为 gbk 或者utf8版本) 首先下载ucenter 之后,解压之后,upload  里的 ...

  10. 更新一波题解(最近做的三个dp题)

    很久没写题解了,去ec之前来填一填坑,希望能攒攒人品... 首先是去年上海F题..uvalive7143 题意: 给n个人分 m间房子,每个房间的容量是已知的,其中有k对双胞胎,双胞胎可以看作相同的人 ...