在VB.NET中设计构造函数或结构

时间:2014-04-18 00:40:03

标签: vb.net oop constructor structure

我正在学习Visual Basic .NET(面试)。

我对正确的数据结构(可能是构造函数,结构或其他数据结构)有疑问。

例如,

  1. 我们可能有10台或更多台电视(TV1,TV2,TV3 ......)
    • 每台电视都有一个或三个独特的频道(低,中,高)(例如,45,100和135)
    • 每个频道(低,中,高)可以选择黑白屏幕,彩色屏幕或两者
  2. 每台电视有五种频率(Frq_1,Frq_2等)
    • 每个频率(Frq_1,Frq_2等)有七个唯一的频率设置,即一对整数值。例如,Frq_1 - > < 1,3> Frq_2->< 1,5-> ... ..
  3. 我是VB.NET的初学者,所以我不确定如何以及如何设计数据结构。

    如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

屏幕类型可以描述为枚举,其余使用类和属性,例如

Enum Screen
    MonoChrome
    Color
    Both
End Enum

Class Channel
    Property Number As Integer
    Property Screen As Screen
End Class

MustInherit Class Channels
End Class

Class OneChannel
    Inherits Channels
    Property Channel As Channel
End Class

Class ThreeChannels
    Inherits Channels
    Property Low As Channel
    Property Medium As Channel
    Property High As Channel
End Class

Class Setting
    Property First As Integer
    Property Second As Integer
End Class

Class Frequency
    Property Set_1 As Setting
    Property Set_2 As Setting
    Property Set_3 As Setting
    Property Set_4 As Setting
    Property Set_5 As Setting
    Property Set_6 As Setting
    Property Set_7 As Setting
End Class

Class TV
    Property Channels As Channels
    Property Frq_1 As Frequency
    Property Frq_2 As Frequency
    Property Frq_3 As Frequency
    Property Frq_4 As Frequency
    Property Frq_5 As Frequency
End Class

Module Module1
    Sub Main()
        Dim tvs(10) As TV
        // ...
    End Sub
End Module