Is there anything you can do with a C # event that you cannot do with a VB event?

My friend is primarily a VB developer, and he says over and over how much easier it is to write events to VB than C #. My problem is that it is probably easier, but if there weren’t a reason for the extra complexity, they probably would have done it just as easily in C #. Can someone tell me if there is any added flexibility or any abilities, in general, what can be done with C # events and not with VB.Net events?

+3
source share
5 answers

The only thing that comes to mind for C # is the ability to subscribe to the void return event (almost all events) with an anonymous function. VB.Net 9.0 only supports Lambda Expressions expressions that return a value (this is fixed in VB 10.0).

VB has a bit of flexibility not present in C # regarding events

  • Support for Relaxed Delegates . This allows VB to use event handlers that require only a subset of the parameters in the event type (mainly used with empty parameter functions)
  • The Handles clause makes it much easier to delete constructor events, not C #, where you need to dig through the .Designer.cs file.
  • RaiseEvent keyword makes null event verification problem non-existent in VB.Net
+4
source

VB # , .

, , VB.Net . -, null, . , .

Handles. . VB, . . # - / .

: "+=" "AddHandler"?

+2

VB , ?

Public Event OnChange(ByVal Text As String)

, , ...

- RaiseEvent null ( ) ? , .

+1

, , , . , #, + =.

0

# . VB.NET .

0

Source: https://habr.com/ru/post/1705598/


All Articles