活代码LINQ——08
一、模块代码
' 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的更多相关文章
- 活代码LINQ——09
一.代码 ' Fig. 9.7: LINQWithListCollection.vb ' LINQ to Objects using a List(Of String). Module LINQWit ...
- 活代码LINQ——06
一.模块代码 ' Fig. 9.4: LINQWithArrayOfObjects.vb ' LINQ to Objects using an array of Employee objects. M ...
- 活代码LINQ——01
序言 此系列的所有代码都是运行在Win 7 64位 + Visual Basic 2008 Express Edition的环境中 之所以学习List集合类,是因为我们先前学习的数组自身的缺陷: 1. ...
- 活代码LINQ——07
来源说明:https://blog.csdn.net/sha574810590/article/details/40738069 在LINQ中,数据源和查询结果实际上都是IEnumerable< ...
- 活代码LINQ——05
片段代码: ' Exercise 9.3 Solution: Invoice.vb ' Invoice class. Public Class invoide ' declare variables ...
- 活代码LINQ——04
一.主模块代码: 'Fig.4.16:GradeBookTest.vb 'Create and manipulate a GradeBook object;illustrate validation ...
- 活代码LINQ——03
一.主模块代码: 'Fig.4.13:GradeBookTest.vb 'GradeBook constructor used to specify the course name at the 't ...
- 活代码LINQ——02
一.复习基础——属性与实例变量 'Fig. 4.8:GradeBookTest.vb 'Create and manipulate a GradeBook object. Module GradeBo ...
- Linq to EF 与Linq to Object 使用心得
大家都知道Linq既可以用来查询数据库对象(我这里指的是Entity FrameWork里的Model对象),也可以用来查询内存中的IEnumerable对象. 两者单独查询时都不会出现什么问题,不过 ...
随机推荐
- Python3 tkinter基础 Text image 文本框中插入图片
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Spring Boot 监控利器 —— Actutor
参考 CSDN-学习Spring Boot:(二十七)Spring Boot 2.0 中使用 Actuator 使用Actuator监控Spring Boot应用 程序猿DD-Spring Boot ...
- 2019-4-21 - plan
设计模式 idea中demo 在test1中使用单例测试ok
- 详解Python的装饰器
Python中的装饰器是你进入Python大门的一道坎,不管你跨不跨过去它都在那里. 为什么需要装饰器 我们假设你的程序实现了say_hello()和say_goodbye()两个函数. def sa ...
- Lintcode228-Middle of Linked List-Naive
228. Middle of Linked List Find the middle node of a linked list. Example Example 1: Input: 1->2- ...
- 应对 Visual Stdio 编译时出现错误:常量中有换行符
笔者最近用 Visual Stdio 时,发现一个问题,在某一次写完语言进行编绎运行时,出现了以下错误: C2001错误:变量中有换行符 C2413错误:语法错误 缺少")"(在& ...
- 技巧 筛1~n的所有因子
从 i : 1~n, 是i的倍数, 则计入该数 复杂度 n*(1/1+1/2+1/3+...1/n)=nlogn ll d[N]; // 计每个数的因子数 set<ll> s[N]; // ...
- Android人脸识别Demo竖屏YUV方向调整和图片保存
本博客包含三个常用方法,用于盛开Android版人脸识别Demo中竖屏使用时送入yuv数据,但一直无法识别的情况. 1.首先可以尝试顺时针旋转90°或270°,然后送入识别SDK. 2.旋转方向后依然 ...
- python pyqt绘制直方图
# -*- coding: utf-8 -*- """ In this example we draw two different kinds of histogram. ...
- Python自学:第三章 根据值删除元素
motorcycles = ["honda", "yamaha", "suzuki", "ducati"] print( ...