Jef*_*ern 2 .net vb.net generics
这是我正在尝试开发的代码:
Public Structure Statistic(Of t)
Dim maxStat As t
Dim curStat As t
Public Sub New(ByVal pValue As t)
maxStat = pValue
curStat = pValue
End Sub
Public Property Level() As t
Get
Return curStat
End Get
Set(ByVal value As t)
curStat = value
If curStat > maxStat Then curStat = maxStat
End Set
End Property
End Structure
Run Code Online (Sandbox Code Playgroud)
它不会编译,因为我收到一个错误,'>'没有为T和T的类型定义.无论如何,我可以指定约束,保证T是一个数字类型?
这是我在用户进行更改和建议后目前所拥有的.它仍然无法正常工作.我是否必须将T的值更改为IComparable?必须有一些非常简单的东西,我搞砸了.
Public Structure Statistic(Of T As IComparable(Of T))
Dim maxStat As T
Dim curStat As T
Public Sub New(ByVal pValue As T)
maxStat = pValue
curStat = pValue
End Sub
Public Property Statistic() As T
Get
Return curStat
End Get
Set(ByVal value As T)
If value > maxStat Then
End If
End Set
End Property
End Structure
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3380 次 |
| 最近记录: |