一、代码

' 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. 将markdown文档使用gulp转换为HTML【附带两套css样式】

    将markdown文档使用gulp转换为HTML[附带两套css样式] 今天遇到一个需求,即将Markdown文档转为为HTML在网页展示,身为一名程序员,能用代码解决的问题,手动打一遍无疑是可耻的. ...

  2. IP包设计

    IP包 IP核(Intellectual Property core)就是知识产权核或知识产权模块的意思,用于配置FPGA或其它硅芯片上的逻辑资源. 引用链接https://blog.csdn.net ...

  3. thinkphp3.2升级至thinkphp5.0.24

    view文件 修改文件名 把tp3.2.3\app\module\view文件夹下所有文件夹拷贝至tp5\app\module\view 打开cmd命令窗口,cd至view文件夹下,执行dir /b ...

  4. P2822 组合数问题

    传送门 思路: 利用公式: C( n,r ) = C( n-1,r ) + C( n-1,r-1 ) 由此可以将计算 C( n,r ) 的过程化为加法来做. 可以看出,C( n,r ) 其实就是求杨辉 ...

  5. 【编程语言】extern "C"让C++与C进行混合编程

    最近工作不算轻松,现在作为一个项目的负责人统一管理着前端.后端.设计.产品,身上肩负着不小责任,虽然有压力但是对于自己也是一种锻炼.同时自己也在负责整个后端的架构设计,虽然后端经验不是很多,但是自己正 ...

  6. Django 应用程序 + 模型 + 基本数据访问

    如果你只是建造一个简单的web站点,那么可能你只需要一个app就可以了.如果是复杂的象 电子商务之类的Web站点,你可能需要把这些功能划分成不同的app,以便以后重用. 确实,你还可以不用创建app, ...

  7. windows下用c++调用caffe做前向

    参考博客: https://blog.csdn.net/muyouhang/article/details/54773265 https://blog.csdn.net/hhh0209/article ...

  8. python 学习笔记 2 ----> dive into python 3

    Python Shell idle的使用 >>> >>>help() ----> help> 可以在help这个工具中查找Python内置函数的文档等等 ...

  9. 使用npm私有服务器保存公司内部强业务类型组件(二):vue-webpack框架

    一套基于vue webpack element-ui的npm私有服务器开发组件框架 下载 在配置的有两个地方需要注意: 1:配置library library选项: 如果设置此选项,会将bundle导 ...

  10. Android测试(二)——adb常用命令

    连接设备: 安装应用包apk文件: adb install apk文件 卸载应用: adb uninstall 包名 将设备中的文件放到本地: adb pull 设备文件目录 本地文件目录 将本地文件 ...