No increment operator in VB.net

后端 未结 5 1846
春和景丽
春和景丽 2020-12-15 03:41

I am fairly new to vb.net and came across this issue while converting a for loop in C# to VB.net I realized that the increment operators are not available in vb.net (++ and

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 04:11

    The following extension methods replicate ++x x++ --x x--

    Public Module INC_DEC
    
      
      Public Function PreINC(ByRef x As Integer) As Integer
        Return Interlocked.Increment(x)
      End Function
    
      
      Public Function PostINC(ByRef x As Integer) As Integer
        Dim tmp = x
        Interlocked.Increment(x)
        Return tmp
      End Function
    
      
      Public Function PreDEC(ByRef x As Integer) As Integer
        Return Interlocked.Decrement(x)
      End Function
    
      
      Public Function PostDEC(ByRef x As Integer) As Integer
        Dim tmp = x
        Interlocked.Decrement(x)
        Return tmp 
      End Function
    End Module
    

提交回复
热议问题