一、模块代码

' 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. git忽略对已入库文件的修改

    项目开发过程中,会遇到本地配置文件每个开发人员不同的情况,但如果遇到类似数据库配置这种最终需要加入 git 版本控制的配置,则会陷入两难境地.要么不跟踪,要么有人提交后其他人同步下来必须手动修改,非常 ...

  2. 8位、16位、32位单片机中的“XX位”指什么?

    32位单片机的32位是指单片机的“字长”,也就是一次运算中参与运算的数据长度,这个位是指二进制位. 如果总线宽度与CPU一次处理的数据宽度相同,则这个宽度就是所说的单片机位数. 如果总线宽度与CPU一 ...

  3. foreach循环里不能remove/add元素的原理

    foreach循环 ​    foreach循环(Foreach loop)是计算机编程语言中的一种控制流程语句,通常用来循环遍历数组或集合中的元素.Java语言从JDK 1.5.0开始引入forea ...

  4. 二、Python数据类型(一)

    一.Python的基本输入与输出语句 (一)输出语句 print() 示例: print('你好,Python') print(4+5) a = 10 print(a) 输出的内容可以是字符串,变量, ...

  5. 解决ubuntu无法使用root用户启动Google Chrome浏览器

    1.找到Chrome的路径 # whereis google-chrome google-chrome: /usr/bin/google-chrome /usr/share/man/man1/goog ...

  6. vbuffer.hpp

    //vov #ifndef VBUFFER_HPP #define VBUFFER_HPP #include <iostream> #include <deque> #incl ...

  7. JAVA程序设计的第一次作业

    这是我第一次接触博客,刚开始用博客很生疏,感觉很麻烦,但是后来慢慢从老师那里了解到了许多博客可以带给我们的便利.通过博客,我们不仅可以记录自己从刚开始进入程序学习的懵懵懂懂到后来想要学,想深究,想探讨 ...

  8. libcrypto.so.1.0.0: no version information available

    openssl-1.0.1p源码安装后,依赖于openssl.so库的应用报错libcrypto.so.1.0.0: no version information available 解法:1. 创建 ...

  9. 【Java】【10】后台处理Emoji表情

    问题:存到数据库的emoji表情,取出来后,在前端显示为乱码 环境:SpringBoot + Oracle(MySQL据说是支持表情的) 解决方案: 引入emoji相关的jar包,使用很方便,不过表情 ...

  10. document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题

    转自http://wo13145219.iteye.com/blog/2001598 一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取do ...