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

后端 未结 21 1830
渐次进展
渐次进展 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:31

    VB.NET has support for CIL Exception Filters, C# doesn't:

    Try 
      ...
    Catch ex As SomeException When ex.SomeProperty = 1
      ...
    End Try 
    
    0 讨论(0)
  • 2020-12-05 06:31

    In C# you have to assign your variable before you can use it. I think you can turn this off, but it's the default behavior.

    So something like this:

    int something;
    if (something == 10)
    { ... }
    

    Isn't allowed, but the VB equivalent would be.

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

    The semi-colon that ends up every line in C# is prohibited in VB, and that always makes me smile when I try going back to VB.Net...

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

    The VB 9.0 compiler automatically translates literal XML into "functional construction" syntax. The C# compiler does not support this nice literal XML syntax.

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

    One of my favorites (and bummers)

    In VB.Net you can struture a switch/case statement as such:

    Select Case True
    
       Case User.Name = "Joe" And User.Role = "BigWig" And SecretTime = "HackerTime"
          GrantCredentials()
    
    End Select
    

    which allows you to evaluate some complex evaluations through a switch instead of a variety of if/else blocks. You cannot do this in C#.

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

    Global variables don't exist in c# i think

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