zoukankan      html  css  js  c++  java
  • 活代码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 

  • 相关阅读:
    派生类的构造函数
    继承和派生
    自增自减运算符的重载(强制类型转换运算符重载)
    流插入和流提取运算符的重载
    动态数组类的设计
    函数的返回值
    赋值运算符的重载
    运算符重载
    常量对象函数引用和参数传递
    理解ASP.NET MVC的路由系统
  • 原文地址:https://www.cnblogs.com/xiehaofeng/p/10060827.html
Copyright © 2011-2022 走看看