一、代码

' Fig. 9.7: LINQWithListCollection.vb
' LINQ to Objects using a List(Of String).
Module LINQWithListCollection
Sub Main()
' populate a List of Strings
Dim items As New List(Of String)
items.Add("aqua") ' add "aqua" to the end of the List
items.Add("rust") ' add "rust" to the end of the List
items.Add("yellow") ' add "yellow" to the end of the List
items.Add("red") ' add "red" to the end of the List ' select Strings starting with "r" and convert them to uppercase
Dim startsWithR = _
From item In items _
Where item.StartsWith("r") _
Order By item _
Select item.ToUpper() ' display query results
For Each item In startsWithR
Console.Write("{0} ", item)
Next Console.WriteLine() ' output end of line items.Add("ruby") ' add "ruby" to the end of the List
items.Add("saffron") ' add "saffron" to the end of the List ' print updated query results
For Each item In startsWithR
Console.Write("{0} ", item)
Next Console.WriteLine() ' output end of line
End Sub ' Main
End Module ' LINQWithListCollection ' **************************************************************************
' * (C) Copyright 1992-2009 by Deitel & Associates, Inc. and *
' * Pearson Education, Inc. All Rights Reserved. *
' * *
' * DISCLAIMER: The authors and publisher of this book have used their *
' * best efforts in preparing the book. These efforts include the *
' * development, research, and testing of the theories and programs *
' * to determine their effectiveness. The authors and publisher make *
' * no warranty of any kind, expressed or implied, with regard to these *
' * programs or to the documentation contained in these books. The authors *
' * and publisher shall not be liable in any event for incidental or *
' * consequential damages in connection with, or arising out of, the *
' * furnishing, performance, or use of these programs. *
' **************************************************************************

  二、运行结果:

来源:Visual Basic 2008 How to  Program           P305

活代码LINQ——09的更多相关文章

  1. 活代码LINQ——06

    一.模块代码 ' Fig. 9.4: LINQWithArrayOfObjects.vb ' LINQ to Objects using an array of Employee objects. M ...

  2. 活代码LINQ——01

    序言 此系列的所有代码都是运行在Win 7 64位 + Visual Basic 2008 Express Edition的环境中 之所以学习List集合类,是因为我们先前学习的数组自身的缺陷: 1. ...

  3. 活代码LINQ——08

    一.模块代码 ' Fig. 9.6: ListCollection.vb ' Generic List collection demonstration. Module ListCollection ...

  4. 活代码LINQ——07

    来源说明:https://blog.csdn.net/sha574810590/article/details/40738069 在LINQ中,数据源和查询结果实际上都是IEnumerable< ...

  5. 活代码LINQ——05

    片段代码: ' Exercise 9.3 Solution: Invoice.vb ' Invoice class. Public Class invoide ' declare variables ...

  6. 活代码LINQ——04

    一.主模块代码: 'Fig.4.16:GradeBookTest.vb 'Create and manipulate a GradeBook object;illustrate validation ...

  7. 活代码LINQ——03

    一.主模块代码: 'Fig.4.13:GradeBookTest.vb 'GradeBook constructor used to specify the course name at the 't ...

  8. 活代码LINQ——02

    一.复习基础——属性与实例变量 'Fig. 4.8:GradeBookTest.vb 'Create and manipulate a GradeBook object. Module GradeBo ...

  9. Linq to EF 与Linq to Object 使用心得

    大家都知道Linq既可以用来查询数据库对象(我这里指的是Entity FrameWork里的Model对象),也可以用来查询内存中的IEnumerable对象. 两者单独查询时都不会出现什么问题,不过 ...

随机推荐

  1. 使用guava过期map

    最近需要将微信的accesstoken保存到缓存里面,防止重复请求微信接口获取token,造成token请求次数超标,其实随便一个缓存都可以轻松解决,但是现有的环境中没有redis,没有memcahe ...

  2. 清除本地SVN信息

    C:\Documents and Settings\yangxf\Application Data\Subversion\auth 这个目录下删除svn文件夹即可

  3. jsp中的绝对路径、相对路径和访问jsp的方式

    1.jsp的绝对路径 绝对路径在复制jsp时不用修改路径都会正常显示,但是绝对路径${pageContext.request.contextPath}只有jsp可以识别 例如:相对路径:image/l ...

  4. Java 诊断工具 Arthas 教程学习笔记

    Java 诊断利器 Arthas,是阿里的一款开源工具.Github-alibaba/arthas 上可以看到它的介绍.了解它,主要是最近对分析 Java 错误堆栈比较感兴趣,机缘巧合看到了它. 本文 ...

  5. [转载]vb 时间戳与时间互转

    转自:https://blog.csdn.net/boys1999/article/details/23298415 vb 时间戳与时间互转 2014年04月09日 21:13:47 boys1999 ...

  6. 读书笔记--《编写高质量代码:改善Python程序的91个建议》

      第一章 引论 建议写Pythonic式的代码,我理解为充分利用pythonAPI,用最简洁方式写出代码 1.两个变量交换: a, b = b, a 2.翻转list: a = [1, 2, 3, ...

  7. ACM:日历本

    题目描述 我们经常需要使用日历,所以需要一个能生成日历的程序. 先要求你写一个程序,只需要输入年份,就能生成正确的日历. 输入 输入包含多组测试数据.每组输入一个整数Y(1800<=Y<= ...

  8. 使用sphinx制作接口文档并托管到readthedocs

    此sphinx可不是彼sphinx,此篇是指生成文档的工具,是python下最流行的文档生成工具,python官方文档即是它生成,官方网站是http://www.sphinx-doc.org,这里是一 ...

  9. Docker Swarm集群中部署Traefik负载均衡器

    一.创建单节点的Docker Swarm集群 docker swarm init 二.在Swarm集群中创建一个网络 docker network create --driver=overlay tr ...

  10. 雷林鹏分享:CodeIgniter 数据库操作

    在平时项目开发过程中,除了处理那些繁琐的逻辑过程外,还有一个重要的任务就是对数据库的操作处理.这里总结下自己平时使用CI过程中使用的如何对数据库进行操作处理. 在CI框架中,我们一般会把对数据库的操作 ...