活代码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对象. 两者单独查询时都不会出现什么问题,不过 ...
随机推荐
- Java基础学习-Random类和Java数组
1.随机数类(Random) package com.denniscui; import java.util.Random; /* * Random:用于产生随机数 * * 使用步骤: * ...
- XSS漏洞学习笔记
XSS漏洞学习 简介 xss漏洞,英文名为cross site scripting. xss最大的特点就是能注入恶意的代码到用户浏览器的网页上,从而达到劫持用户会话的目的. 说白了就是想尽办法让你加载 ...
- 在微信小程序中将获取到的经纬度(经度纬度)转地址(地名)
var QQMapWX = require('qqmap-wx-jssdk') var qqmapsdk = new QQMapWX({ key: '填写你的key' // 必填 }) wx.getL ...
- Unity3D里怎样隐藏物体
方法很多: 1.改position,移到视野外,推荐,最节省 2.gameObject.SetActive (false); //要提前引用,要不你就改不回来了... 3.renderer.enabl ...
- 8、Dockerfile详解
除了init之外,每一个进程都应该是其他进程的子进程(init是内核启动的),当手动启动nginx时,那么这个nginx就以shell子进程存在.当打开一个命令行提示符时,这个就相当于在运行一个she ...
- Go-For Range 性能研究
文章转载地址:https://www.flysnow.org/2018/10/20/golang-for-range-slice-map.html 如果我们要遍历某个数组,Map 集合.Slice 切 ...
- 兼容ie8的前端下载方法
背景:在xp系统上 ie8浏览器的下载需求,后端返回资源路径. 方法:谷歌下采用aDown下载,ie采用window.open 触发下载,如果不能自动自动下载,采用execCommand(" ...
- sql学习书籍
SQL 入门 在准备成为MySQL DBA之前,能熟练的编写SQL是一个必要条件.exists 和 join之间的等价转换:基本的行列转换:SQL 循环等的熟练掌握对之后的运维和调优工作都有很大的帮助 ...
- 【转】所有版本chrome、chromedriver、firefox下载链接
所有版本chrome.chromedriver.firefox下载链接 1. 所有版本chrome下载 是不是很难找到老版本的chrome?博主收集了几个下载chrome老版本的网站,其中哪个下载的是 ...
- vue页面传值
第一种情况:例:消息列表页(路由)跳转: methods: { goTo(){ this.$router.push({ name:'/My/Info', query:{ 'tellSeq':this. ...