What is allowed in Visual Basic that's prohibited in C# (or vice versa)?

后端 未结 21 1829
渐次进展
渐次进展 2020-12-05 06:07

This is code-related as in what the compiler will allow you to do in one language, but not allow you to do in another language (e.g. optional parameters in

相关标签:
21条回答
  • 2020-12-05 06:39

    True in VB.Net when converted to an integer will convert to -1 while in C# it will convert to 1.

    Furthermore the NOT keyword in VB.Net is indeed a bitwise NOT (as in C# '~'), and not a logical NOT (C# '!').

    While for the AND and OR operators, VB.Net has already logical operators AndAlso And OrElse which are true logical operators and short circuit, still there is no logical NOT.

    This is especially important when dealing with the Win32 API, in which doing NOT on the result assuming that if the result is True the NOT will negate it, is wrong, since in C true == 1 and therefore a bitwise NOT on 1 is also a true value (and this is in fact probably the reason why in VB true == -1, as this is the only value on which a bitwise NOT will result in 0)

    0 讨论(0)
  • 2020-12-05 06:40

    Indexed properties are allowed in VB.NET, but not in C#

        Private m_MyItems As New Collection(Of String)
        Public Property MyItems(ByVal index As Integer) As String
            Get
                Return m_MyItems.Item(index)
            End Get
            Set(ByVal value As String)
                m_MyItems.Item(index) = value
            End Set
        End Property
    
    0 讨论(0)
  • 2020-12-05 06:40

    The volatile keyword is only available in C# http://www.devcity.net/Articles/160/5/article.aspx

    0 讨论(0)
提交回复
热议问题