Question Visual Studio differences for C# and VB.NET

Lotok

Well-known member
Joined
Jan 17, 2012
Messages
198
Location
Scotland
Programming Experience
5-10
I am switching my language from VB.NET to C#, I accounted for a few weeks of slow coding as I get used to the different syntax which is fine, what I didnt account for is the differences in Visual Studio.

a couple of examples:

1) With VB.NET winforms, visual studio provides a handy dropdown at top for quickly accessing control and form events. This is missing in C#
2) With VB.NET if I write a method for handling an event, much like one that could be generated from the forementioned drop downs, the event will work. In c# I need to go to designer and name the event in the control properties. This seems slow so I am guessign there is a much better way.

If I google the subject I find lots of pages on C# and VB differences but not so much the IDE differences. Does anyone have some good links or reference suggestions?


I have developed VB for about 4 years but the jobn market where I am doesnt really seem to support it :(
 
If you want to know the IDE 'tricks' from more experienced C# developers then asking in a C# forum is probably more rewarding. There is one there: C# Developer Forums
 
VB has two ways of attaching event handlers:

1. A WithEvents field and a Handles clause.
2. An AddHandler statement.

The first is the reason that you can write an event handler in code and not have to go anywhere else to wire it up. You just add the Handles clause and it's done. That's the same reason that VB can offer the drop-downs at the top of the code window. Those drop-downs include all the fields declared WithEvents. You can't do any off that with AddHandler.

The C# mechanism for wiring up events is akin to using AddHandler in VB and there is no equivalent to WithEvents/Handles. The equivalent to this:
VB.NET:
AddHandler someObject.SomeEvent, AddressOf SomeMethod
is this:
VB.NET:
someObject.SomeEvent += SomeMethod;
The C# IDE does offer you some help that VB doesn't though. If you type this:
VB.NET:
someObject.SomeEvent +=
C# will prompt you to press Tab to add the name of a method to handle the event and then press Tab again to generate the method itself.

The thing is though, you should be using the designer to generate the event handlers for any controls or components that you add in the designer. If you select one or more controls or components and then open the Properties window in Events mode, you can double-click and event to generate a method to handle it. VB has that same functionality and it's the best way to create a single method to handle multiple events.
 
Yeah, this probably would have been better suited to the c# forums. I was just wondering if there are other VS quirks to know about.

cheers for the replies fellas.
 
It's really not a VS quirk. It's a language feature that is supported in VB and not C#. That IDE functionality is there in VB to support the VB WithEvents and Handles keywords. Those keywords don't exist in C# so neither does the IDE functionality to support them
 
If you ask me, VB has matured much more nicely than C#. These differences (amongst other) make VB much faster to develop IMO, and code is much more readable in VB than C# (again IMO). I question the job market that does not support VB but does support C#, as both are pretty much the same language with different syntaxes. They plug into each other almost seamlessly.

It's funny how the situation has reversed from the days of VB6 vs VC6. Back then VB was the handicapped language, so more serious developers gravitated to VC, but now it seems VB has the upper hand, and C devs hang tight to old VB stereotypes that no longer apply.

If you are a VB programmer, why not just get a job in VB? You won't make more money as an inexperienced C# programmer than you would as an experienced VB programmer.
 
Fair point JMc, I suppose there is just more to learn than I thought. I'm sure it will fall into place though.
[edit] I am not ignoring the explanation above, I appreciate your time to explain why c# doesnt have that IDE feature. It just shows my lack of c# knowledge. Basic syntax is easy enough but there will be a fair bit to learn. Thanks.[/edit]

I agree with you Herman, I really like VB but that doesn't matter to the 99% of jobs advertised asking for c# developers. VB jobs here aren't easy to come by. I wouldnt market myself as a inexperienced c# developer though. I would market myself as having 4 years .NET development experience using VB.NET & C#. I am making the change now so I can happily write both in the future. I am in a job where the company dont care what language I use so its a good chance to get some c# experience.
 
Last edited:
Back
Top