一、模块代码

' Fig. 9.6: ListCollection.vb
' Generic List collection demonstration.
Module ListCollection
Sub Main()
Dim items As New List(Of String) ' create a new List of Strings items.Add("red") ' append an item to the List
items.Insert(0, "yellow") ' insert the value at index 0 Console.Write( _
"Display list contents with counter-controlled loop:") ' header ' display the colors in the list
For i = 0 To items.Count - 1
Console.Write(" {0}", items(i))
Next ' display colors using For Each...Next in the Display method
Display(items, vbNewLine & _
"Display list contents with For Each...Next statement:") items.Add("green") ' add "green" to the end of the List
items.Add("yellow") ' add "yellow" to the end of the List
Display(items, "List with two new elements:") ' display the List items.Remove("yellow") ' remove the first "yellow"
Display(items, "Remove first instance of yellow:") ' display List items.RemoveAt(1) ' remove item at index 1
Display(items, "Remove second list element (green):") ' display List ' check if a value is in the List
Console.WriteLine("""red"" is {0}in the list", _
If(items.Contains("red"), String.Empty, "not ")) ' display number of elements in the List
Console.WriteLine("Count: {0}", items.Count) ' display the capacity of the List
Console.WriteLine("Capacity: {0}", items.Capacity)
End Sub ' Main ' display the List's elements on the console
Sub Display(ByVal items As List(Of String), ByVal header As String)
Console.Write(header) ' print header ' display each element in items
For Each item In items
Console.Write(" {0}", item)
Next Console.WriteLine() ' print end of line
End Sub ' Display
End Module ' ListCollection ' **************************************************************************
' * (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   P304

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

  1. 活代码LINQ——09

    一.代码 ' Fig. 9.7: LINQWithListCollection.vb ' LINQ to Objects using a List(Of String). Module LINQWit ...

  2. 活代码LINQ——06

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

  3. 活代码LINQ——01

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

  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. HTTP之gRPC

    gRPC 官方文档 gRPC 是一个高性能.开源和通用的 RPC 框架,面向移动和 HTTP/2 设计. gRPC 基于 HTTP/2 标准设计,带来诸如双向流.流控.头部压缩.单 TCP 连接上的多 ...

  2. Qt对象树

    Qt提供了一种机制,能够自动.有效的组织和管理继承自QObject的Qt对象,这种机制就是对象树.子对象动态分配空间不需要释放.

  3. Python+MapReduce实现矩阵相乘

    算法原理 map阶段 在map阶段,需要做的是进行数据准备.把来自矩阵A的元素aij,标识成p条<key, value>的形式,key="i,k",(其中k=1,2,. ...

  4. Kotlin 数据类与密封类

    数据类 Kotlin 可以创建一个只包含数据的类,关键字为 data: data class User(val name: String, val age: Int) 编译器会自动的从主构造函数中根据 ...

  5. 【安卓进阶】Scroller理解与应用

    项目中有个需求,就是在RecyclerView的item中进行侧滑,一开始同事推荐了一个开源库,使用起来确实也方便好用,直接在布局作为父布局即可实现侧滑. 自己也非常好奇这个开源库到底用了什么API能 ...

  6. 【设计模式】抽象工厂模式(Abstract Factory Pattern)

    [前言] 上次针对自己的理解书写一篇工厂模式的文章,后面对于工厂模式进行更加多的学习,于是了解到了抽象工厂模式.其实网上大多数人们都是抽象工厂模式是工厂模式的升级版本,虽然我并不知道所说的升级是什么意 ...

  7. Cocos Creator学习六:加载/释放图片资源

    1.目的:学习加载图片资源.使用图片资源创建对象以及释放图片资源. 2.注意事项以及主要函数: ①注意事项:使用loadRes函数,资源必须放置在assets下的resources文件夹下(默认没有r ...

  8. vue history模式

    注意: 1.前端:config.js路径问题 2.后台:配置nginx

  9. 别让持续交付自动化交付bug

    你的连续交付能力用得还好吗,比如频繁发布移动或云应用的特性增强?还是恰好相反,快速发布了带漏洞的版本? - Joel Shore 连续交付能让交付流程跑得更快,但连续交付本身并不能为发布质量打包票.国 ...

  10. erlang下lists模块sort(排序)方法源码解析(二)

    上接erlang下lists模块sort(排序)方法源码解析(一),到目前为止,list列表已经被分割成N个列表,而且每个列表的元素是有序的(从大到小) 下面我们重点来看看mergel和rmergel ...