活代码LINQ——05
片段代码:
' Exercise 9.3 Solution: Invoice.vb
' Invoice class.
Public Class invoide ' declare variables for Invoice object
Private partNumberValue As Integer
Private partDescriptionValue As String
Private quantityValue As Integer
Private priceValue As Decimal ' four-argument constructor Public Sub New(ByVal part As Integer, ByVal description As String, ByVal count As Integer, ByVal pricePerItem As Decimal)
PartNumber = part
PartDescription = description
Quantity = count
Price = pricePerItem
End Sub ' New ' property for partNumberValue; no validation necessary
Public Property PartNumber() As Integer
Get
Return partNumberValue
End Get Set(ByVal value As Integer)
partNumberValue = value
End Set
End Property ' PartNumber ' property for partDescriptionValue; no validation necessary
Public Property PartDescription() As String
Get
Return partDescriptionValue
End Get Set(ByVal value As String)
partDescriptionValue = value
End Set
End Property ' PartDescription ' property for quantityValue; ensures value is positive
Public Property Quantity() As Integer
Get
Return quantityValue
End Get Set(ByVal value As Integer)
If value > 0 Then ' determine whether quantity is positive
quantityValue = value ' valid quantity assigned
End If
End Set
End Property ' Quantity ' property for pricePerItemValue; ensures value is positive
Public Property Price() As Decimal
Get
Return priceValue
End Get Set(ByVal value As Decimal)
If value > 0 Then ' determine whether price is positive
priceValue = value ' valid price assigned
End If
End Set
End Property ' Price ' return String containing the fields in the Invoice in a nice format
Public Overrides Function ToString() As String
' left justify each field, and give large enough spaces so all the columns line up
Return String.Format("{0,-5} {1,-20} {2,-5} {3,6:C}", PartNumber, PartDescription, Quantity, Price)
End Function ' ToString
End Class ' Invoice ' **************************************************************************
' * (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
活代码LINQ——05的更多相关文章
- 活代码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——08
一.模块代码 ' Fig. 9.6: ListCollection.vb ' Generic List collection demonstration. Module ListCollection ...
- 活代码LINQ——07
来源说明:https://blog.csdn.net/sha574810590/article/details/40738069 在LINQ中,数据源和查询结果实际上都是IEnumerable< ...
- 活代码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基础 Radiobutton 设置相同的value值,产生连锁效果
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 支持向量机(Support Vector Machine):超平面
超平面 超平面是 $n$ 维空间的 $n-1$ 维子空间,类似二维空间的直线,三维空间的平面. 分类学习最基本的想法就是基于训练集D在样本空间中找到一个划分超平面,将不同类别的样本分开.以二维空间为例 ...
- 如何在 Apache 里修改 PHP 配置
当使用 PHP 作为 Apache 模块时,也可以使用 Apache 配置文件(例如:httpd.conf) 和 .htaccess 文件中的指令来修改 PHP 的配置 设定,不过需要有 " ...
- BASE64加解密
- JDK 自带 - Commons Codec 地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi - Bou ...
- Job for docker.service failed because the control process exited with error
Docker 无法启动 报错信息:Job for docker.service failed because the control process exited with error 找了很久才解决 ...
- threejs绕轴转,粒子系统,控制器操作等(二)
前言:threejs系列的第二篇文章,也是一边学习一边总结: 1,一个物体绕着另一个物体转动 上一篇文中主要是物体自转,为了描述一个一个物体绕另一个物体转,这里我描述了一个月球绕地球公转,并且自转的场 ...
- UVA - 11468 (AC自动机+动态规划)
建立AC自动机,把AC自动机当做一张图,在上面跑L个节点就行了. 参考了刘汝佳的代码,发现可能有一个潜在的Bug--如果模式串中出现了没有指定的字符,AC自动机可能会建立出错. 提供一组关于这个BUG ...
- day23
## 复习 4.类与对象的语法class 类名: 代码块(一堆属性与方法)对象名 = 类名() 变量 | 函数 => 属性 | 方法:前者直接使用,通过所属者.语法调用 类会随所属文件加载而加载 ...
- Windows 下 docker 部署 gitlab ci
一.安装 1. 安装 docker Docker下载 注意:Windows 10 家庭版获取 之前的版本不能直接安装 Docker ,而是需要去安装 Docker Toolbox 我这里安装的是 Do ...
- 自定义Cordova插件(基础篇)
cordova自定义插件 注意:存放自定义cordova插件目录不能有空格可能会报错 cordova的安装 下载node.js,安装完成后你可以在命令行中使用node和npm. 安装cordova使用 ...