2014-04-18 32 views
0

我正在学习Visual Basic .NET(面试)。在VB.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> ... ..

我是VB.NET的初学者,所以我真的不知道是什么,以及如何设计数据结构。

我该如何解决这个问题?

+0

一个类将是理想的 - 每一个只是一个属性 – Plutonix

+0

不是构造函数? –

+0

a [构造函数或ctor](http://msdn.microsoft.com/zh-cn/library/2z08e49e(v = vs.90).aspx)是创建类时运行的过程(instanced,实际上)。它不像结构,它的代码,但其中的一些可能被设置在像1a或1ai这样的类构造函数中,因为它听起来像是不会改变的。你最终会得到一个List(Of TVClass)来处理'10或更多'部分 – Plutonix

回答

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