tags:

views:

164

answers:

11

I come from embedded C background. I want to start .NET programming. Should I learn VB or C#? Whats the difference?

+4  A: 

With the latest versions, mostly the difference is in syntax.

VB.NET is much more verbose, C# succinct. The features of the two languages have gotten closer to each other in each version and MS are trying to get them to have feature parity.

With VB.NET, Microsoft tried to keep VB6 programmers happy, with syntax that resembles VB6 (though otherwise the two languages VB6 and VB.NET have very little in common). With C#, the syntax is very C like, so if you have any experience with C, C++, Java, Javascript and the like, you will grasp the basics immediately.

From my experience, certain types of coding are more natural in C# (generics and lambda expressions come to mind).

They both have full access to the BCL and any .NET library, so your choice should not be based on that.

Look at the syntax of both and go with the one you are more comfortable with.

Alternatively, take a look at the programming job board where you live and see which language appears more times and base your decision on that...

Oded
+1  A: 

As Microsoft claims, VB and C# are both first-class languages and "equally powerful" (http://support.microsoft.com/kb/308470), anyway C# is more similar to other OO languages (in fact is very similar to Java) in terms of structures and syntax, so IMHO you should try to learn C# instead of VB.

mamoo
+9  A: 

This is a very contentious question, so I’ll try to be factual and unbiased.

  • C# concise, VB is verbose. If you like languages that use lots of puctuation characters to express structure and operators, C# is your choice. Visual Basic uses words for almost everything (e.g. “and” instead of “&&”, “end” instead of “}“, etc.) and is thus a bit more of a mouthful.

  • C# is the .NET flagship language. You will likely get the newest and greatest language features sooner if you use C#. There is only one feature I’m aware of that VB has and C# doesn’t (XML literals), but this one’s not a big deal. By contrast, Visual Basic is missing some of the really useful features, e.g. iterator blocks.

Except for these considerations, the languages are pretty much the same. In particular, they both use the same underlying libraries (the “.NET Framework”), so all the classes and all the functionality is there in both.

Timwi
A: 

I've used both fairly extensively over the past few years and I would go with C# every time. VB is a nice friendly language as it is particularly verbose, this becomes a real pain when you know C# and what you're missing out on. Simple things like variable declarations take far too many keystrokes in VB for my liking.

One thing that really annoys me about VB.NET is the generics syntax, it's just horrible, and it makes using LINQ really painful.

As a career move, C# would probably be the better bet also as it seems to be the language of the moment. It's also very similar to Java which could be helpful in the future.

Adam Pope
+2  A: 

I work with VB.NET -- because of main application I work on is in VB 6.0 I tried to keep the same flavor of language.

However I would strongly suggest C#. Here are some reasons:

  1. VB has specific syntax. Here are some examples:
    1. Variable declaration in VB is reversed in comparation to other C-like languages. See:
      • VB: Dim n As Long = 1,
      • C#: long n = 1;
        C# version is short and keep standard order of declaration syntax -- type, name, value.
    2. And and Or operators are bit operators and short-circuit won't work with them (which implies that the whole condition is parsed, which could lead to some errors -- i.e. If Not obj is Nothing And obj.length = 1 then cause error if obj is null).
      In VB.NET there are new operators AndAlso and OrElse which support short-circuit .
  2. Most examples of code use C# -- sometimes it's hard to translate them in VB -- especially if you don't know the C#.
  3. VB.NET is much more verbose.
  4. VB.NET is not VB6 which makes hard to switch from VB to VB.NET.
Grzegorz Gierlik
Not `standard order`, but `C-like` and `non-Pascal` order
abatishchev
`VB.NET is not VB6` I wish this would be true...there are too many programmers around which abuse VB.NET as VB6 replacement. :(
Bobby
A: 

I suggest that you start learning C#, but also look up the syntax in VB as you learn.

C# is a bit stricter and shows what's actually happening, while VB does a little more to hide what's actually going on to the programmer. So, regardless of which language you end up using, you will have a better understanding of what's going on if you know how it's done in C#.

It's good to know at least a little of both languages, as some examples are only available in one of them. It's better to understand the original code than to use an automated translation, as it usually ends up containing awkward constructs that makes it hard to understand.

Guffa
A: 

VB.Net and C#.Net all get compiled down to the same CLI code, so choice of language is personal preference.

As already mentioned VB.Net kept the VB6 programmers happy by keeping similar syntax. The syntax to be feels quite foreign but then again I started with Java and C.

The idea of VB been verbose is true, like some functional languages there are more keywords to indicate the end of statements as such there are far fewer braces/brackets in VB.Net than C#.Net.

Although some of the differences have been covered, I would recommended you learn C#.Net, once you know C#.Net you should have no problem reading someone else's VB.Net code anyway. The interest bit is whether you learn the C++ CLI as well as C#.

JonWillis
A: 

A great and wider thing to ask. In my view, in a single words C#. There are lot of differences both Vb.net and C# also, we like C# also you have idea of C you definitely like C#.

I have great experience for the same, I started my carriers in C/C++ then dive in Java and my organization push me into .Net on the first launch. They dig me into VB.net I struggled many things and finally I decided I have to go with C#.

In these days vb.net grew up but still it is not preferable. Differences are already given by others in above.

Welcome in the world of .Net

Rick
+1  A: 

always c# over VB.NET. the later just seems too clunky and old hat for the mordern world today!!

Roooss
A: 

Another difference is that VB has simplified many constructs and does things not visible to the programmer. A few things I remember:

Nothing and empty string is same in VB but not i C#:

If someString = "" Then

is the same as

if (string.IsNullOrEmpty(someString))

End condition in loops are only evaluated once in VB:

For ii = 0 To list.Count

is the same as

int count = list.Count;
for (int ii = 0; ii < count; ++ii)

Method arguments are not evaluated in the same order

Dim sw as New StopWatch()  
sw.Start()  
Comparer.Default.Compare(b:=sw.ElapsedTicks, a:=sw.ElapsedTicks)

will not generate the same result as

var sw = new StopWatch();  
sw.Start();  
Comparer.Default.Compare(b: sw.ElapsedTicks, a: sw.ElapsedTicks);
adrianm
A: 

I Guess c# is more heavily adopted. but VB.net is there for people that aren't true developers (maybe they have come from an access vba background). besides all the m$ certifications allow you to choose your language preference before you sit an exam so either is fine in their books!

Roooss