I have a team with people that are quite comfortable in C# but we got a requirement to write a project in VB.net. How hard would it be to think in C# and on the fly convert to VB?
Is that doable?
Could you list the issues that we can come across?
I heard that VB.net doesn't have closures. Is that still true for .net 3.5?
If you are approaching VB.Net with the mindset of C# it's best to set the following options in the project
Option Strict On
Option Explicit On
Option Infer On
This essentially removes the late binding semantics of VB.Net and forces it to be a strictly typed language. This will make it closer to C# semantic wise (still not exact by any means).
VB.Net has Lambda Expression (and hence Closure) support starting with the Visual Studio 2008 / .Net Framework 3.5 release. Not expression and not Statement. Statement lambdas are not supported until VS2010 / .Net Framework 4.0. Although you can use the 4.0 compiler to downtarget 2.0 frameworks.
As C# and VB.NET uses the same framework and compile to very similar IL code, you have a lot for free. Writing Basic syntax instead is not that hard.
The C# syntax is more aimed at showing what's going on, while the VB syntax often hides away some details, so a C# programmer is already familiar with some concepts that may not at all obvious to a VB programmer. In some ways learning C# is a better way to learn how VB works than to learn VB itself...
I frequently answer VB.NET questions in different forums mostly based on my C# knowledge, and I still haven't written anything more than short test programs in VB.NET myself.
There are of course some quirks to look out for in VB. Like the / operator for example that always converts both operands to double, or the = operand that uses VB specific comparison code rather than the comparison specified for the equality operator in the .NET classes.
One area that VB.NET tends to try and cover up is working with events; others have briefly touched on some of the differences, but here's a little more on them:
VB.NET provides a WithEvents keyword for fields that raise events. If the field is declared WithEvents then you can add a Handles field.Event to the end of a method whose signature is compatible with the event; that method will automatically be a delegate of the event without needing to manually AddHandler and RemoveHandler (+= and -=).
Private WithEvents SomeField
Public Sub SomeField_SomeEvent(sender as Object, e as EventArgs) Handles SomeField.SomeEvent
Console.Writeline("SomeEvent occured")
End Sub
Event declarations and raising events are simplified a bit. VB.NET doesn't require that you check if an event is null prior to notifying listeners:
Public event SomeEvent as EventHandler(of SomeEventArg)
Public Sub SomeMethod()
RaiseEvent SomeEvent(Me, new EventArgs)
End Sub
One "hidden" feature of events in VB.NET is accessing the underlying MulticastDelegate, to do something like GetInvocationList() Note: the event is named SomeEvent and the code to access the multicastdelegate calls an invisible field named SomeEventEvent:
Public event SomeEvent as EventHandler(of SomeEventArg)
Public Sub SomeMethod()
// Note that SomeEvent's MulticastDelegate is accessed by appending
// another "Event" to the end, this sample is redundant but accurate.
// If the event was named ListChanged then it would be ListChangedEvent
dim invocationList = SomeEventEvent.GetInvocationList()
End Sub
One of the biggest issues I've found is the apparent verbosity of VB. It has all these big keywords like MustInherit, NotInheritable, MustOverride, etc., where C# just has things like sealed, abstract and virtual. You have to have an End to everything (End Sub, End Function, End While, End Namespace, End Class, etc.) And you have to explicitly mark read-only properties with the ReadOnly keyword; simply omitting the setter won't fly. Also remembering AndAlso and OrElse instead of the more intuitive (but non-short-circuiting) And and Or, and things like Is Nothing and IsNot Nothing instead of == null or != null.
None of these are necessarily problems with the language, but if you're accustomed to the relative simplicity of C#, VB code may look like a whole lot of extra stuff to you.
There were some useful articles in Visual Studio magazine back in Jan 2008.
What C# developers should know about VB
And for completeness, What VB developers should know about C#
You might also be interested in the question "what's allowed in VB that is prohibited in C# (or vice versa)"
A point which hasn't been mentioned here is that field initializers in C# run before the base constructor, while those in VB run between the base constructor and the first "real" statement of the derived-class constructor (after the base-constructor call, if any). This makes it possible for field initializers in a derived class to make use of base-class members (which may have been initialized using parameters passed to the constructor), but also means that if the base-class constructor of an object passes itself anywhere before it returns, the partially-constructed object may get used before all the field initializers have run. In C#, all of the field initializers will run before the base constructor starts execution, but none of the field initializers will be able to use the partially-constructed object.
PS--if any of the Microsoft people behind C# read this, would there be any particular difficulty adding a context-sensitive keyword for field declarations to specify whether they should be processed before or after the base constructor, or possibly have them performed by some special method that could be called from the constructor, which could be wrapped in a try-finally block (so any IDisposables thus allocated could be cleaned up) and might also be able to make use of parameters passed to the constructor?
I find this to be a handy article in highlighting the differences. I'm a vb.net programmer, and this helps me figure out c# code, so I'm sure it will work the other way!
http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx
Just like any language (human or computer), you first learn to "translate in your head," then you eventually start "thinking" in the other language.
The quicker your team can make that leap, the better. So, do it the same way the experts tell you to learn a human language: real-world examples and immersion.
There are a few C# to VB.NET conversion utilities available online, so start by having the team write in C#, convert to VB.NET, and clean it up. (The conversion utilities vary in quality and have some limitations, especially with newer language features.)
Once they get the hang of the basic "grammar," drop them into VB.NET 100%.
I use both every day, often in different code windows at the same time, and have no problem context-switching or doing the "right thing" in each.
Apart from what Jared has already mentioned you should have no problems in doing this. The only other source of irritation is weird defaults. E.G. Did you know that VB.NET projects, by default hide the references node in solution explorer? (you have to select ShowAllFiles to see it).
Appreciating the age of this question, this one is probably quite well known now, but I'll add the one biggest gotcha I have seen in terms of writing VB.NET like a C# user:
Nothing does not mean null, it means default(T)
This means that...
Dim a As Integer = Nothing
Dim b As Integer? = Nothing
...is entirely valid, and effectively means...
int a = default(int); // 0
int? b = default(int?); // null
John M Gant's answer touches on the fact that there are dedicated keywords for comparing to Nothing-meaning-null -- Is Nothing and IsNot Nothing but, if you forget and use =, you might get an unexpected result which is hard to track down:
Dim a As Integer? = Nothing
If a = Nothing Then Console.WriteLine("a = Nothing")
If a <> Nothing Then Console.WriteLine("a <> Nothing")
If a Is Nothing Then Console.WriteLine("a Is Nothing")
If a IsNot Nothing Then Console.WriteLine("a IsNot Nothing")
'Output:
'a Is Nothing
This one is at least caught by a compiler warnings (BC42037 and BC42038), so you might want to force those warnings to be errors in your VBPROJ file.
I think C# to VB.NET won't be too painful, it's just a case of learning a new syntax. In the current versions the capabilities of both languages are fairly closely aligned.
The other way round (VB.NET to C#) could be harder because people might be used to making use of the 'My' namespace and other things put in there to make VB6 developers feel at home.
There are some subtle differences you'll have to watch out for. For example VB.Net has no concept of short circuiting an if statement (I was corrected that apparently it does). If it just a short term project, you probably won't have a problem, but different languages do have different approaches to solving the same problem. An example of this is Python programmers talking about doing things in the "pythonic" way. They talk about this concept in the book Dreaming in Code where java programmers were trying to program java using the python syntax. It leads to taking the long way around to solving a problem. Will this happen with C# and VB.Net? It is hard to say, they both use the underlying frame work, so the differences won't be huge, but it would still help to try and learn how to use VB.NET the way it was intended.
Edit: so apparently, it does has the concept of short circuiting, but it doesn't do this by default where C# does. This just further proves the point of learning how the language functions can be beneficial in the long term.
I don't think it would be too hard. VB.NET and C# are languages that are close to each other, only the syntax really differs. Of course it's going to take some time for your team to get used to the new language, but I don't think you'll run into big problems.
Oh, and VB.NET does have closures. It's missing a few other features from C# like the yield keyword, multi-statement lambdas and auto properties, but nothing very critical.
One option if you don't feel like writing the vb.net code is to write your project in C#, compile it, and use Reflector to see what the vb.net equivalent looks like. It all compiles down to MSIL anyway!
Related
This may be a dumb question - but why are shared methods availible on types and instances in VB.net - am I wrong to assume they are the equivalent to C# static methods?
i.e
MyClass.MySharedMethod()
dim mc as new MyClass()
mc.MySharedMethod()
Why am I allowed to do this? What possible advantage is there to this - all I can see this doing is confusing people when using intellisense. I'm sure this has to do with some convention from classic VB6 by why bother bring this up to .NET - it just seems so broken to me.
Yes, it's basically a hangover from VB6. Java lets you do this too, but most IDEs warn you these days I believe.
And yes, it's a really bad idea. The most obvious example of it being bad is Thread.Sleep:
Dim t as new Thread(...)
t.Sleep(1000)
Which thread is sleeping? The current one. Doh!
This may be a dumb question - but why are shared methods availible on types and instances in VB.net - am I wrong to assume they are the equivalent to C# static methods?
They are the same. VB will warn if you try to use them on instances but it's not forbidden. This has probably got to do with dynamic typing and late binding. Imagine that you've got a late-bound object (Object) without knowing its exact type. How would you go about calling a static method of its class?
As far as I know, this wouldn't be possible in C# (without resorting to reflection). In VB with Option Strict Off, you could simply call it as an instance method of the object.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
What in C#.NET makes it more suitable for some projects than VB.NET?
Performance?, Capabilities?, Libraries/Components?, Reputation?, Reliability? Maintainability?, Ease?
Basically anything C# can do, that is impossible using VB, or vice versa.
Things you just have to consider when choosing C#/VB for a project.
C# and VB are basically the same however there are some minor differences. Aside from the obvious grammar differences you have the following differences:
C# can call unsafe code
VB has optional parameters (Coming in C#4.0)
VB is easier to use when making late bound calls (Coming in C# 4.0) This and number make 2 make using VB to do office automation much cleaner.
VB has a bunch of "helper" functions and class like the My namespace; however, all of this are accessible to C#
VB is case insensitive
C#'s syntax follow a similar grammar to c and java, which make it a much more comfortable transition from those languages, where as VB can be more comfortable to VB users. As far performance, and libraries or components they are nearly identical.
As for which one to choose, unless you have a need to do unsafe operations, then choose the language which is most natural to you. After years of being a VB developer I loved not having to write If yadada then.....End If if (yadaya){....} saves my carpal tunnel a few extra keystrokes (Which can then be used on answering SO questions)
Edit
Just learned one more difference btw C# and VB is that VB supports filtered exceptions so you could something like this pseudo:
try
{
//do something that fails
}
catch(Exception ex when ArgumentException,
ArgumentNullException, FormatException)
{
//Only handle these three types
}
This should not be confused with the ability to do:
try
{
//something that fails
}
catch(ArgumentException)
{
//Log Error
}
catch(ArgumentNullException)
{
//Log Error
}
In this case you are going to handle the exceptions differently in the VB world you could define one piece of code to handle multiple types of Exceptions.
Edit
Some more differences.
VB's Is operator compares two objects to determine if they are the same it compiles to the CEQ IL instruction where as C# compiles to isinst IL. So the following are equivalent statements
c#
if (foo is FooObject){}
vb
If TypeOf foo is FooObject then
Also as mentioned in the comments and I wish I could see them to give you credit but C# doesn't have a like parameter. You need to use the RegEx class.
I think this blog post by Kathleen Dollard provides an excellent overview to the question:
What a C# Coder Should Know Before They Write VB
and her first advice is:
1) Get over the respect thing or quit
before you start. VB is a great
language.
Street cred among geeks.
(And don't pretend that's not important!)
Others have covered a lot of the differences - as has been said several times, they're nearly equivalent languages. A few differences which haven't been covered as far as I've seen:
VB9 has:
XML literals
Mutable anonymous types (urgh)
More LINQ support in the language (C# only covers a few operators)
A whole bunch of extra bits in the language which get compiled down to calls to the Microsoft.VisualBasic assembly. (C# prefers to be a small language with the weight of the .NET framework behind it.)
DateTime literals
C# 3 has:
Better support for lambda expressions: IIRC, you can't write a lambda expression with a block body in VB.
Iterator blocks.
Syntax for extension methods (instead of decorating the method with an attribute)
I suspect there is more, but I thought I'd just throw those into the mix.
When you hit a problem, you'll often be able to Google for a code sample that shows how to solve it in minutes. This is a significant factor in improving productivity. When I was working with Delphi, I had to convert code samples from C into Object Pascal - doable, but tedious, i.e. lots of friction. So don't underestimate the fact that...
The vast majority of .Net code samples are in C# !
In early versions of VB.NET, the difference was more obvious, however with the current version, there are no significant differences.
VB supports XML literals directly in code, which is not supported by C#. C# supports unsafe code and VB don't. Technically these two are the biggest differences. There are many small variations but they are not important. I like C# more because I think the syntax is much less bloated. It's easy to recognize the blocks of code instead of seeing a bunch of keywords, but that's a pure personal preference.
Choose the one you and your team are more familiar with.
VB.Net has a root namespace and C# has a default namespace which is not the same. Because when you have a root namespace in VB.Net it will always add that before the namespace.
For example: if you have a rootnamepsace in VB.Net named namespace1 and then you add this to your file.
Namespace namespace1
Public Class class1
End Class
End Namespace
then you will have to refer to it as namespace1.namespace1.class1
in C# if you have a default namespace called namespace1 and you this in your file.
namespace namespace1{
public class class1{}
}
Then you can still just refer to it as namespace1.class1
My favorite feature of C# that VB doesn't have is the yield statement. It lets you easily return an lazily evaluated IEnumerable from a method.
Here is an article that covers it: http://msdn.microsoft.com/en-us/magazine/cc163970.aspx
VB has a better feedback on errors. In C# you have to compile more often to get all the errors in your syntax.
The big advantage i see with C# is that the vast majority of open source projects, sample code and blog snippets are written in C#. Although it’s easy to convert these to VB.NET with tools (or your head) it is still a monotonous task for VB devs (like me).
Even if you write in VB.NET day to day, you will still need to be able to read C#
Technically, they share the same framework with same performance and memory characteristics and same type systems, so I find it hard to hard to split the two.
Most good developers should be able to shift between the two with a few days adjustment time.
My core frustaration lies with the hundreds of time I have written:
String lastName as String
and wondered why it never compiles!
In C# you can have more fine tuned control over events/delegates. But you rarely need this.
There are a lot more code examples for C#.
In VB.Net it is (a lot) easier to use late binding. For example to COM objects (in C# from version 4.0).
I use C# for 90% in my projects
I use VB.Net for interop to Excel, etc
As soon as I know F# better, I will probably use it for the parts that F# is better suited for.
Performance?
No difference, though VB historically uses a weird indexing in loops which means that you have to subtract 1 from the highest index most of the time:
For i = 0 To someArrayOrString.Length - 1 …
Though I doubt this impacts performance in any measurable way.
On the other hand, due to background compilation, VB actually compiles seemingly faster. Some people claim that this makes the IDE react sluggishly but I've never noticed that myself.
Capabilities?
In a few instances, C#'s yield statement is really useful. VB requires more manual work here. Also, lambdas are much better implemented in C#, especially syntactically. Consider these two statements:
Parallel.For(1, 10000, i => {
// Do something
});
versus
Parallel.For(1, 10000, Sub() _
' Do something '
End Sub)
Besides the fact that VB can't do this yet, and that a comment at this place is forbidden, it's just more clutter and generally a no-go.
Libraries/Components?
Identical.
Reputation?
Not important. “Street cred”? Sorry. Not a factor. Get over it, Nick.
Reliability?
Maintainability?
Ease?
More or less identical. I claim that VB is easier but that may be biased and in any way, it's only marginal.
As I understand it, there are differences between the languages though they are minimal. I would suggest working with the language that you/your developers would feel most comfortable with. If they already have VB experience then I'd suggest VB.Net/vice-versa.
Though I prefer the terse syntax of C# personally. :)
Since C# and VB.Net both compile into MSIL, both have nearly identical Performance, Capabilities, Libraries and Components. Reflection can deassemble MSIL code into either C# or VB.NET (or a number of other languages)
This basically leaves us with, C# looks a lot like Java and C++ which gives it more credibility.
I think Josh gave a good rollup on the language differences.
Tooling Support
There are however also differences in how Visual Studio handles these languages.
Code Snippets are easier to use from the C# editor and the refactoring is better also.
The VB-editor simplifies intellisense by not showing all options at all times.
I'm sure there are more things, but those are the ones that I as a C#'er (doing very little VB) have noticed.
Here is another point not yet covered in this trail:
Higher Degree of Employability + Better (more) Dev Resources
Now I don’t agree with this point of view however:
There are more C# dev shops that VB shops
Some backward c# employers will put you at a serious disadvantage if you are stronger with VB. So maybe C# is the better choice here.
On the flip side, when you go to hire people for your C# project, you will be able to attract more candidates to iterview and get better skills as a result – I don't think detail should be overlooked.
I have to say it's been my experience when using Google to search for examples or documentation that C# examples are of better quality than VB examples. This isn't to say that there aren't bad C# examples, but if you search for something like "dictionary drop down" adding C# will provide a better quality answer higher on the list.
This doesn't apply to examples that display both C# and VB code side by side.
for the moment VB.Net has a very poor implementation of lambda expressions. Meaning that you can't do the neat things that you can in C#. Well you can, but it needs a very ugly workaround in most cases.
This is solved in VB.Net 10.0.
Free from old cruft, array declaration in C# is not padded with extra element. VB.NET array is padded with extra element, so legacy VB6 code migration is easier.
C# is more consistent than VB.NET
Button1.Color() = Color.Red
Button1.Color = Color.Red
I can't give an answer when one student asked me when to use parenthesis on properties of VB.NET. It's hard to give an insightful reasoning for this kind of misfeature.
Consistency with instance and static members. VB.NET allows accessing static members on instance e.g. yarn.Sleep(1000), this is a misfeature. https://stackoverflow.com/questions/312419/language-features-you-should-never-use
In a recent VB.NET project I adopted the naming conventions I'm used to using in C#. Namely, often calling a variable the same name as the class it references, only with a different case, e.g.
Foo foo = new Foo(); // C#
Dim foo As New Foo() ' VB.NET
I find this is often the clearest way to write code, especially for small methods. This coding style obviously works fine in C#, being case sensitive, and because of the syntax highlighting provided by Visual Studio, it is very easy to see that the class name and the variable name are different.
However, to my surprise, this also worked fine nearly 100% of the time* in VB.NET. The only issue was that the variable name then appeared to take on a multiple identity. Namely it could be used to call both instance methods and Shared (static) methods of the Foo class. This didn't really cause any problems though, it just meant that Intellisense would provide a list containing both static and instance methods after you hit the '.' after the variable name.
I found, again to my surprise, that this didn't actually lead to any confusion in my project, and it's been very successful so far! However I was the only person working on this particular project.
Here is a slightly longer example:
Dim collection as Collection = New Collection()
For Each bar As Bar in Bar.All()
collection.SomeInstanceMethod(bar)
Next
collection.SomeSharedMethod()
* The only issue I found with this was that sometimes the 'Rename' refactoring tool got confused, i.e. when renaming a class it would rename the variables with the same name as the class as well, in their declaration lines (Dim foo As...), but not the other references to that variable, causing compiler issues (duh). These were always easy to correct though.
Another small annoyance is that the VB.NET syntax highlighter doesn't highlight class names any differently than variable names, making it not quite as nice as when using it in C#. I still found the code very readable though.
Has anyone else tried allowing this in a team environment? Are there any other potential issues with this naming convention in VB.NET?
Although VB is case-insensitive, the compiler is intelligent enough to not being confused between the object-instance and the class.
However, it's certainly very dangerous and wrong to use the same name in a case-insensitive language! Especially if other programmers are working on that project.
I have to move back and forth between VB and C#, and we consider this poor practice. We also don't like letting variable names in C# differ from their type only by case. Instead, we use an _ prefix or give it a more meaningful name.
Whenever you start a new language it's inevitable you'll notice a bunch of things that are different and miss the old way of doing things. Often this is because you are initially unaware of different features in the other language has that address the same problem. Since you're new to VB, here are a couple notes that will help you get things done:
It's not 100% correct to say that VB.Net is case-insensitive unless you also make the point that it is case-aware. When you declare an variableidentifier, the IDE will take note of what case you used and auto-correct other uses to match that case. You can use this feature to help spot typos or places where the IDE might be confused about a variable or type. I've actually come to prefer this to real case-sensitive schemes.
VB.Net imports namespaces differently. If you want to use the File class, you can just say IO.File without needing to import System.IO at the top. The feature especially comes in handy when learning a new API with a few nested namespace layers, because you can import a top-level section of API, type the next namespace name, and you'll be prompted with a list of classes in that namespace. It's hard to explain here, but if you look for it and start using it, you'll really miss it when going back to C#. The main thing is that, for me at least, it really breaks my flow to need to jump to the top of the file to add yet another using directive for a namespace I may only use once or twice. In VB, that interruption is much less common.
VB.Net does background compilation. The moment your cursor leaves a line, you know whether or not that line compiles. This somewhat makes up for not highlighting class names, because part of why that's useful in C# is so you know that you typed it correctly. VB.Net gives you even more confidence in this regard.
I'm going to differ with the rest of the answers here... I don't think there is any problem with doing this. I do it regularly, and have absolutely 0 problems resulting from it.
If you use lowercase for the variable name you can easily differentiate the variable from the type, and the compiler will not confuse the two identifiers.
If you delete the variable declaration, the compiler will think other references to this variable now refer to the type, but it's not really a problem because those will be tagged as errors.
I have done the same thing in the past. I'm starting to move away from it though because Visual Studio will occasionally get confused when it auto formats the code and changes the casing on my static method calls to lower case. That is even more annoying than not being able to differentiate the variable and class names by case only. But, purely from technical perspective it should not cause any issues.
As Moayad notes, the compiler can tell the difference--but it's bad practice that can lead to maintenance issues and other side effects.
A better practice all-around is to try to name the variable in the context they're being used, rather than just the type name. This leads to self-documenting code and requires fewer comments (comments are greatly abused as an excuse to write dense code).
It's only safe as long as the compiler can always tell whether Foo means the class or the variable, and eventually you'll hit a case where it can't. Eric Lippert discusses the sort of thing that can go wrong on his blog.
I use this convention all the time, and it's never been a problem. The most natural name for a variable is often the class name, and therefore that's what you should call it (Best name for an arbitrary Line? line.).
The only downside is when some tool interprets the context incorrectly. For example, visual studio 2010 beta 1 sometimes uses the class highlight on variables named the same as the class. That's a bit annoying.
Context sensitivity is much closer to how I think than case sensitivity.
Well, this isn't the final answer, and I don't think there is a definitive one, but the general opinion seems to be that it's not a good idea to use this naming convention! There must be one true way to write nice VB.NET variable names though, and I don't like any of the alternatives...
Here are links to the official Microsoft guidelines for anyone who's interested, although they don't seem to cover this particular question (please correct me if I've missed it).
Visual Basic Naming Conventions: http://msdn.microsoft.com/en-us/library/0b283bse.aspx
Declared Element Names: http://msdn.microsoft.com/en-us/library/81ed9a62.aspx
Cheers all!
VB.NET isn't case sensitive! This equates to:
Foo Foo = new Foo(); // C#
As a standard in our team environment we would use:
Dim oFoo as New Foo 'VB.NET
Would having a nice little feature that makes it quicker to write code like Automatic Properties fit very nicely with the mantra of VB.NET?
Something like this would work perfect:
Public Property FirstName() As String
Get
Set
End Property
UPDATE: VB.NET 10 (coming with Visual Studio 2010 and .NET 4.0) will have Automatic Properties. Here's a link that shows a little info about the feature: http://geekswithblogs.net/DarrenFieldhouse/archive/2008/12/01/new-features-in-vb.net-10-.net-4.0.aspx
In VB.NET 10 Automatic Properties will be defines like this:
Public Property CustomerID As Integer
One reason many features get delayed in VB is that the development structure is much different than in C# and additionally, that often more thought goes into details. The same seems to be true in this case, as suggested by Paul Vick's post on the matter. This is unfortunate because it means a delay in many cases (automatic properties, iterator methods, multiline lambdas, to name but a few) but on the other hand, the VB developers usually get a much more mature feature in the long run (looking at the discussion, this will be especially true for iterator methods).
So, long story short: VB 10 will (hopefully!) see automatic properties.
It also wasn't as big of a pain point in vb.net, since visual studio will automatically create 90% of the skeleton code of a property for you whereas with C# you used to have to type it all out.
If you want to do properties a little quicker, try code snippets.
Type:
Property
and just after typing the "y", press the Tab key :-).
I realize this doesn't answer the particular question, but does give you what the VB team provided...
I know this post is old so you may already know but VB is getting Auto Properties in next version of VS.
Based on response to feedback and Channel9.
C# and VB.NET don't exactly line up on new features in their first versions. Usually, by the next version C# catches up with some VB.NET features and vice versa. I kind of like literal XML from VB.NET, and hoping they add that to C#.
There's no particular reason really. It's been always been the case that even when VB.NET and C# are touted to be equally powerful (and to be fair, they are) their syntaxes and some of the structures sometimes differ. You have two different development teams working on the languages, so it's something you can expect to happen.
automatic properties are not necessary in vb
the concession one makes by using an automatic property is that you can not modify the Get and Set.
If you dont require those, just make a public data field.
VB has had automatic properties for years. They just called them something else.
Certainly there's the difference in general syntax, but what other critical distinctions exist? There are some differences, right?
The linked comparisons are very thorough, but as far as the main differences I would note the following:
C# has anonymous methodsVB has these now, too
C# has the yield keyword (iterator blocks)VB11 added this
VB supports implicit late binding (C# has explicit late binding now via the dynamic keyword)
VB supports XML literals
VB is case insensitive
More out-of-the-box code snippets for VB
More out-of-the-box refactoring tools for C#Visual Studio 2015 now provides the same refactoring tools for both VB and C#.
In general the things MS focuses on for each vary, because the two languages are targeted at very different audiences. This blog post has a good summary of the target audiences. It is probably a good idea to determine which audience you are in, because it will determine what kind of tools you'll get from Microsoft.
This topic has had a lot of face time since .Net 2.0 was released. See this Wikipedia article for a readable summary.
This may be considered syntax, but VB.NET is case insensitive while C# is case sensitive.
This is a very comprehensive reference.
Since I assume you can google, I don't think a link to more sites is what you are looking for.
My answer: Choose base on the history of your developers. C# is more JAVA like, and probably C++ like.
VB.NET was easier for VB programmers, but I guess that is no really an issue anymore sine there are no new .NET programmers coming from old VB.
My opinion is that VB is more productive then C#, it seems it is always ahead in terms of productivity tools (such as intelisense), and I would recommend vb over c# to someone that asks. Of course, someone that knows he prefers c# won't ask, and c# is probably the right choice for him.
Although the syntax sugar on C#3 has really pushed the bar forward, I must say some of the Linq to XML stuff in VB.Net seems quite nice and makes handling complex, deeply nested XML a little bit more tolerable. Just a little bit.
One glaring difference is in how they handle extension methods (Vb.Net actually allows something that C# doesn't - passing the type on which the extension method is being defined as ref): http://blog.gadodia.net/extension-methods-in-vbnet-and-c/
Apart from syntax not that much any more. They both compile to exactly the same IL, so you can compile something as VB and reflect it into C#.
Most of the apparent differences are syntactic sugar. For instance VB appears to support dynamic types, but really they're just as static as C#'s - the VB compiler figures them out.
Visual Studio behaves differently with VB than with C# - it hides lots of functionality but adds background compiling (great for small projects, resource hogging for large ones) and better snippet support.
With more and more compiler 'magic' in C#3 VB.Net has really fallen behind. The only thing VB now has that C# doesn't is the handles keyword - and that's of debatable benefit.
#Tom - that really useful, but a little out of date - VB.Net now supports XML docs too with '''
#Luke - VB.Net still doesn't have anon-methods, but does now support lambdas.
The biggest difference in my opinion is the ability to write unsafe code in C#.
Although VB.NET supports try...catch type exception handling, it still has something similar to VB6's ON ERROR. ON ERROR can be seriously abused, and in the vast majority of cases, try...catch is far better; but ON ERROR can be useful when handling COM time-out operations where the error can be trapped, decoded, and the final "try again" is a simple one line.
You can do the same with try...catch but the code is a lot messier.
This topic is briefly described at wikipedia and harding.
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Visual_Basic_.NET
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
Just go through and make your notes on that.
When it gets to IL its all just bits. That case insensitivity is just a precompiler pass.
But the general consensus is, vb is more verbose.
If you can write c# why not save your eyes and hands and write the smaller amount of code to do the same thing.
One glaring difference is in how they handle extension methods (Vb.Net actually allows something that C# doesn't - passing the type on which the extension method is being defined as ref): http://blog.gadodia.net/extension-methods-in-vbnet-and-c/
Yes VB.NET fixed most of the VB6 problems and made it a proper OOP language - ie. Similar in abilities to C#. AlthougnI tend to prefer C#, I do find the old VB ON ERROR construct useful for handling COM interop timeouts. Something to use wisely though - ON ERROR is easily abused!!