[.net] The differences between C# and VB?

Started by
7 comments, last by joelmartinez 17 years, 4 months ago
Hi there! I've chosen Visual Basic.NET because of the simple syntax and I've allways heard that it doesn't matter what language you use in .NET, they will act the same way. I've allways believed it but often questioned it. Now I change the ever asked question "Which one is the best", and instead I ask you: What are the differences, if any, between C# 2.0 and Visual Basic 2005? Why do Microsoft leave VB in the dark and advertise C#? Why do people generally choose C# before VB? Why are almoust every .NET article Microsoft write in C#? Thank you.
Advertisement
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html
Quote:Original post by Zyndrof
What are the differences, if any, between C# 2.0 and Visual Basic 2005?

Different syntax? VB.Net is a natural progression for people who previously used other versions of VB. C# is easy to get to grips with if you come from another language of the C family.
Beyond the syntax, they're pretty much the same though, as they both build on .NET. (There are even online converters for converting code between the two languages.)

Quote:
Why do Microsoft leave VB in the dark and advertise C#?

The cynical guess is that MS already "controls" all VB development. They have nothing to gain by advertising VB because anyone who would be interested in the language already use it.

C# opens up to the entire mass of Java/C/C++ developers. All of those might consider C# because of its similarity to "their" languages, and all of them firmly believe anything Basic to be evil personified.

That said, do they "leave VB in the dark"? It's very well supported, *every* code sample on msdn exists in VB as well as C#. And anything .NET works just fine with VB.

Quote:
Why do people generally choose C# before VB?

See above. Because 1) anything Basic has a pretty bad name, and 2) because C# is similar to what most programmers are used to.

Quote:
Why are almoust every .NET article Microsoft write in C#?

Are they? I've seen an awful lot of VB only articles. And as I said, all of the documentation provides code samples for both languages, as well as C++.

Other than that, it could be becase it makes no difference? The .NET framework libraries are the same no matter which language you use, and any decent programmer should be able to at least read a language like C#, so porting it to VB should be trivial for most people. And for the same reason, some articles are in VB only. Because hey, the author felt more comfortable in that language, and any C# programmer should be able to figure out what was going on anyway.
I am neither a C# or VB programmer so I may not be particularly qualified to answer this but I do work in an office with a VB team and they have told me that C# is extremely similar to VB.NET. They had to port some code to C# and their exact words were "We just had to add some curly brackets". I can't help thinking that it may have taken a little more thatn that though. Maybe they are trying to migrate all of the VB programmers over to C# so that they can phase out VB altogether? I've heard a couple of the VB programmers here saying that they want to get more into C# and .NET in case they ever need to find another job. Anyway, as I've said, this is just from what I hear at the office.

Microsoft do seem to be pushing C# quite a bit lately, especially with their XNA Game Studio Express which is exclusively C#.
I refer you to my previous answer on this subject.

I prefer C# for its less convoluted syntax, enforced (by default) type safety, unsafe code blocks (something VB cannot do) and less bothersome Intellisense dialog. I can switch between the two quite easily though.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

1) C# has a lot of the optimization options and type-safe strictness turned on by default. VB.NET has them turned off by default. Beyond that, I cannot see any difference. Furthermore, they both compile to the same IL and if they are both configured the same (settings-wise) then the IL is identical.

2) VB has a HUGE following... VB6 did anyway. A lot of VB programmers were ticked beyond belief with VB.NET because it threw a lot of things that VB6 clinged to. Furthermore, a lot of programmers claimed VB.NET was SLOWER than VB6... but this is only half-true. If you use VB6 syntax in VB.NET, it will run slower than a VB6 application. However, if you use the VB.NET syntax and avoid the built-in functions placed in VB.NET for VB6 backwards compatibility, then your program will run faster.

3) I believe this is due to the common misconception that C# is faster than VB.NET. However, C# and VB.NET are the same speed when configured to compile similarly.

4) There are a lot of DirectX articles on Microsoft written in C#. However, I think there are a lot of VB.NET examples popping up. Also, if you just have a little patience when looking at the C# code, you can easily translate the two as their syntax is very similar.

Just my two pennies.
Enoch DagorLead DeveloperDark Sky EntertainmentBeyond Protocol
C# is a real language and VB is not. However, MS has already dropped support for C# in directX, so you might want to stick with C++ for now.
Quote:Original post by Anonymous Poster
C# is a real language and VB is not. However, MS has already dropped support for C# in directX, so you might want to stick with C++ for now.
[rolleyes]

Have you ever heard of XNA? And you do know that Microsoft is exploring the possibilities of an official MD3D10? Both those aside, MDX 1.1 is a complete DirectX 9 managed implementation and still a supported product.

The main differences between C# and VB.NET have already been discussed quite fully so I have nothing further to add there [smile]

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Just to add completeness to the post ... VB.NET will not run (as of v1) on the xbox 360 (source).

Quote:Q: Can I use this call-a-DLL approach to write Xbox 360 XNA Game Studio Express games for other non-C# CLR languages like Iron Python or Visual Basic?

A: Unfortunately no, not for those two specific languages. (Sorry!) The reason is that the Xbox 360 version of the XNA GSE CLR is based on the .NET Compact Framework 2.0. This is a problem for Iron Python and Visual Basic because those particular languages rely on CLR features that are not present in the .NET Compact Framework 2.0. Therefore you will get a runtime error when you try and run your Iron Python or Visual Basic code on the 360. It's possible that future versions of either the languages or the Xbox 360 GSE runtime will fix this problem. (But don't hold your breath -- nobody has promised anything in these areas. Only C# is officially supported for XNA GSE games.)

Note that this limitation to run on top of the .NET Compact Framework only applies to the Xbox 360 version of your game. Although I have not tried it, I believe that it should be possible to use a variation of the techniques in Part 2 to run Iron Python and/or Visual Basic XNA GSE games on Windows.

Alan Phipps has written set of tutorials on Using Visual Basic with XNA GSE on Windows
Joel Martinez
http://codecube.net
[twitter]joelmartinez[/twitter]

This topic is closed to new replies.

Advertisement