Learning C# for VB.NET Programmers
I’ve finally decided that it’s time to learn C#. I’ve just graduated from a year long VB.NET certificate program at the University of Washington so I’m feeling really comfortable with the Visual Studio 2005 IDE and with the .NET Framework classes etc. Given that, I figured the learning curve shouldn’t be too steep. So, I thought I’d talk about some of the differences I noticed between the VB.Net and C# environments the very first time I created a new C# project. This isn’t a debate about which language is superior or even two cents from a super great C# veteran. It’s just what a VB.NET programmer noticed the first time I ventured onto creating a C# application. In fact, some of this may seem trivial, but if you’ve never created a C# application before…well, there’s a first time for everything, even the little stuff. So if you’re making the switch from VB.NET to C#, I hope you will find this interesting.
- Refactoring built into the IDE. This is really cool. It’s a tool that will change all the instances of a variable in your program when you decide to rename it, help you move blocks of code, delete code, and much more. It’s built in so when you change the name of a variable, or do anything that might require its assistance, it will automatically prompt you for help. For those of you who are VB.NET programmers and don’t know about refactoring but would like to try it out, there is a free refactoring tool available for VB.NET from here. They have versions for VS 2002, 2003, and 2005.
- Ok, this one took me some time to figure out. In VB.NET, the code window has two dropdown boxes at the top, the left dropdown box has the name of the controls/classes/form instances and the right one has the built in events for the selected control. However, in C#, the dropdown boxes are there, but the controls and events are not. It seems that they are populated with existing types and members only. It took me a fair amount of time to find the built in events. So hopefully, if you are reading this and are considering trying out C#, this will save you some time. The events are available through the properties window in the design view. At the properties window for the control you want to program an event for, click on the yellow lightning bolt to view the available event. Then double click on the event you want and a method skeleton will be built for you in the code window.
- No Me or My keywords. This is unfortunate. I really got used to those two little words and I would have to argue they should be in C#, especially My. I love My.Computer. It gives me direct access to the system sounds, the clipboard, the keyboard, the mouse, etc. I will also miss My.Settings very much when using C#. This was the handiest way to store, access, and persist application and user settings. I haven’t figured out how to save user and application settings in C# yet, but when I do, I will post it here.
- Of course, the syntax is very different and resembles C++ and Java. Fortunately, this did not prove to be trouble for me. Actually, it brings me back to college. My instructors were Unix gurus and only allowed us to use C, C++ and Java for our projects. Unmanaged C++ was the very first language I learned and even though I haven’t used it in a couple of years, I think this is the reason learning the C# syntax was so easy for me. In fact, there really wasn’t any learning, I just started typing it out. For those of you who are pure VB.NET developers and never really delved into the Java or C++ world, you might encounter a slight learning curve. But in reality, it’s not that big of a deal and you will be able to catch on quickly with a little practice.
Things that are the same:
- Of course, both languages use the .Net Framework and thus both have access to the same namespaces, classes, and libraries. This is what makes it so easy to switch from one language to another. Managed code definitely is cool!
- Both are fully OOP languages.
- Both have the same design view, same controls are available, etc.
My preference:
Frankly, I don’t prefer one over the other and I think it would be unfair of me to pick one because of my lack of experience with C#. As I start to use features available in VB.NET but not in C# and visa versa (C# lets you write “unsafe code (pointers)”), I think I will be able to make a more fair assessment. Then again, this isn’t about which language is better…why is it so easy to start making comparisons
Filed under: VB.NET (All), C# (All) on July 1st, 2006
Leave a Reply
You must be logged in to post a comment.