【发布时间】:2011-03-13 21:30:50
【问题描述】:
我的结构实际上是一个具有更多功能的简单字节。
我是这样定义的:
Structure DeltaTime
Private m_DeltaTime As Byte
Public ReadOnly DeltaTime As Byte
Get
Return m_DeltaTime
End Get
End Property
End Structure
我想拥有这两个功能:
Public Sub Main
Dim x As DeltaTime = 80 'Create a new instance of DeltaTime set to 80
Dim y As New ClassWithDtProperty With { .DeltaTime = 80 }
End Sub
有没有办法做到这一点?
如果有一种从结构继承的方法,我会简单地从字节继承添加我的功能,基本上我只需要一个具有自定义功能的字节结构。
当您想定义新的单例成员值类型(例如,您想定义一个半字节类型等)并且您希望能够通过分配给 number 来设置它时,我的问题也是有效的或其他语言类型的表示。
换句话说,我希望能够定义以下 Int4 (nibble) 结构并按如下方式使用它:
Dim myNibble As Int4 = &HF 'Unsigned
【问题讨论】:
标签: vb.net operators implementation value-type assignment-operator