本文介绍了VB多态性构造函数默认值和属性。类似Listbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在我的头撞墙。
我试图创建一个类,用于存储数据的人与另一个类存储他们的银行交易。

I've been banging my head against a wall for sometime on this one.I'm trying to create a class for storing data on People with another class to store their Bank Transactions.

理想情况下,这一切都被隐藏离开只有简单的语句,声明和函数可用于程序员。这些将包括:

Ideally, this all be hidden away and leave only simple statments, declarations and functions available to the programmer. These will include:


  • Dim Client as New ClientList

  • Clients.Count'readonly integer

  • Clients.Add(S)

  • Clients.Refresh()

  • Clients(n).Remove()

  • Clients(n).Transaction.Add()

  • Clients(n).Transaction(n).Remove()

  • Dim Clients As New ClientList
  • Clients.Count 'readonly integer
  • Clients.Add("S")
  • Clients.Refresh()
  • Clients(n).Remove()
  • Clients(n).Transaction.Add()
  • Clients(n).Transaction(n).Remove()

我知道这是可能的,因为这些存在于Listbox类中,虽然不能弄清楚它是如何完成的。

I know this is possible as these exist in the Listbox Class though can't figure out how it's done.

任何帮助将不胜感激。
提前感谢!

Any help would be appreciated.Thanks in advance!

推荐答案

创建交易 a 客户

Public Class Transaction
    'TODO: Implement Transaction
End Class

Public Class Client
    Public ReadOnly Transactions As List(Of Transaction) = New List(Of Transaction)

    Public Sub New(ByVal name As String)
        Me.Name = name
    End Sub

    Public Name As String
End Class

创建 ClientList

Public Class ClientList
    Inherits List(Of Client)

    Public Overloads Sub Add(ByVal name As String)
        Add(New Client(name))
    End Sub

    Public Sub Refresh()
        ' Do what ever you want Refresh to do
    End Sub
End Class

您可以像这样使用客户列表

You can then use the client list like this

Dim clients As New ClientList

clients.Add("S")
' Or
clients.Add(New Client("T"))

Dim n As Integer = clients.Count
Dim m As Integer = clients(0).Transactions.Count

clients.Refresh()
clients.RemoveAt(5)
clients(n - 1).Transactions.Add(New Transaction())
clients(n - 1).Transactions.RemoveAt(2)
Dim name As String = clients(0).Name
Dim client As Client = clients(0)

这篇关于VB多态性构造函数默认值和属性。类似Listbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 00:19