代码之家  ›  专栏  ›  技术社区  ›  Jeffrey Kern

泛型类(T)-从VB.Net的一系列类型中指定

  •  2
  • Jeffrey Kern  · 技术社区  · 14 年前

    这就是我要开发的代码:

      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
    

       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
    
    2 回复  |  直到 14 年前
        1
  •  4
  •   mattmc3    14 年前

    干得好。。。这应该管用。

    Public Structure Statistic(Of t As {IComparable})
       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.CompareTo(maxStat) > 0 Then curStat = maxStat
          End Set
       End Property
    End Structure
    

    Public Structure Statistic(Of t As {Structure, IComparable}) .

        2
  •  7
  •   Matt Hamilton    14 年前