Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Difference between events in c# and vb.net

Difference between events in c# and vb.net

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpquestionlearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    ddecoy
    wrote on last edited by
    #1

    Why can't we make an event in c# without a delegate as eventhandler, like you can in vb.net ?

    Learning without thought is labor lost; thought without learning is perilous. (Confucius)

    D T 2 Replies Last reply
    0
    • D ddecoy

      Why can't we make an event in c# without a delegate as eventhandler, like you can in vb.net ?

      Learning without thought is labor lost; thought without learning is perilous. (Confucius)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Events in C# and VB.NET work the same way. If you're refering to the WithEvents keyword, it's just syntactic sugar for having the manual stuff done for you.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      1 Reply Last reply
      0
      • D ddecoy

        Why can't we make an event in c# without a delegate as eventhandler, like you can in vb.net ?

        Learning without thought is labor lost; thought without learning is perilous. (Confucius)

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        If you don't want to bother creating your own custom delegate you have two other choices in c# 1. Use an inline delegate. 2. Use Generics eg. EventHandler In VB.Net you also have two options in addition to creating a custom delegate> 1. Use Generics 2. Use WithEvents WithEvents works rather differently as it gives you rather more than just syntactic sugar, it also deals with reattaching the event handlers to the new object if you change the object referenced. You can even define the event handlers before initialising the object that raises the events. In C# you have to do that yourself, and you have to have an instance before you can hook up events. So, C# or VB.NET you can roll your own. C# you get inline delegates VB.NET you get less code for complicated event handling scenarios. Personally I would rather have a little more code that shows me what is really going on. Then it is easier to realise I didn't need half of it in the first place!

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        D 1 Reply Last reply
        0
        • T The Man from U N C L E

          If you don't want to bother creating your own custom delegate you have two other choices in c# 1. Use an inline delegate. 2. Use Generics eg. EventHandler In VB.Net you also have two options in addition to creating a custom delegate> 1. Use Generics 2. Use WithEvents WithEvents works rather differently as it gives you rather more than just syntactic sugar, it also deals with reattaching the event handlers to the new object if you change the object referenced. You can even define the event handlers before initialising the object that raises the events. In C# you have to do that yourself, and you have to have an instance before you can hook up events. So, C# or VB.NET you can roll your own. C# you get inline delegates VB.NET you get less code for complicated event handling scenarios. Personally I would rather have a little more code that shows me what is really going on. Then it is easier to realise I didn't need half of it in the first place!

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          D Offline
          D Offline
          ddecoy
          wrote on last edited by
          #4

          Excellent reply. Again c# seems to be a lot clearer.

          Learning without thought is labor lost; thought without learning is perilous. (Confucius)

          T 1 Reply Last reply
          0
          • D ddecoy

            Excellent reply. Again c# seems to be a lot clearer.

            Learning without thought is labor lost; thought without learning is perilous. (Confucius)

            T Offline
            T Offline
            The Man from U N C L E
            wrote on last edited by
            #5

            Thanks. I use c# for my own projects, and VB.Net at work, so I get to see both sides of the coin, and struggle to get the two to do the same. I do prefer the flexibility and control in c#, but some of the RAD tools embedded in VB.Net are excellent. I wish it were possible to code classes in the same project in different languages so I could use the most appropriate one for the task at a class level. If that included managed C++ for some of the restricted stuff like Extended MAPI then even better.

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups