As a C programmer, you will definitely be much more comfortable with C#, at least with the syntax which tends to be less verbose than Visual Basic. Here's an example to declare a class.
Visual Basic
Public Class MyClientClass
Implements IMyClient
Private _id As Integer
Private _company As String
Private _phoneNumber As Long
''' <Summary>
''' Constructor...
''' </Summary>
Public Sub New()
End Sub
Public ReadOnly Property Id As Integer Implements IMyClient.Id
Get
Return _id
End Get
End Property
Public Property Company As String Implements IMyClient.Company
Get
Return _company
End Get
Set (ByVal value As String)
If (String.IsNullOrEmpty(value)) Then Return
_company = value.Trim()
End Property
Public Property PhoneNumber As Long
Get
Return _phoneNumber
End Get
Set (ByVal value As Long)
_phoneNumber = value
End Set
End Property
End Class
C#
public class MyClientClass : IMyClient {
private string _company;
/// <summary>
/// Constructor...
/// </summary>
public MyClientClass() { }
public int Id { get; private set; }
public string Company {
get {
return _company;
} set {
if (string.IsNullOrEmpty(value)) return;
_company = value.Trim();
}
}
public long PhoneNumber { get; set; }
}
The above C# code is valid only from version 3.0, as it handles the getters and setters through an in-memory generated variable that you, as a programmer, don't need to care about when you do not require special handling, but to assign and to retrieve the property's value.
Visual Basic explicit implementation can be fun when you want to rename the implementations of your proerties or methods. C# doesn't allow so, but permits implicit implementation by the method's or property's name.
In short, since you have so much experience with the C syntax, and C++ keywords such static
, abstract
, etc. you'd rather go with C#. Your learning will seem a lot easier for you. Then, keep in mind that both languages are using the .NET Framework. So, as long as you stick with the .NET Framework, you will become fluent in both languages in no time, this will only be a matter of syntax afterwards.
For example:
abstract
(C#) = MustInherit
(VB)
internal
(C#) = Friend
(VB)
static
(C#) = Shared
(VB)
virtual
(C#) = MustOverride
(VB)
and so forth.
In the end, it may be no more truthful with .NET 4.0 coming out, but even in .NET 3.5, C# had many advantages over VB.NET as for stuff you could do in C#, and couldn't in VB. C# is (or was before .NET 4.0) THE language with which Microsoft wanted to launch its .NET platform. As a matter of fact, plenty of interesting technical stuff you could do with C# couldn't be done with VB. For instance, the use of InternalsVisibleToAttribute
in .NET 2.0.
The InternalsVisibleToAttribute
is similar to the C++ keyword friend, which allows one assembly to access internal
members osf an alien assembly. Very practical for testing. Making your internal members of your core assembly visible to your testing assembly saves you lot of work with reflection. In .NET 2.0, it's available and functional in C#, but not in VBNET 2.0. (See here for further information).
Using lambda expressions is very funny when you can use them. In VBNET, the keyword used for a lambda expression is Function
. However, if you had to use a lambda expression which doesn't actually return a value, you had to work around like illustrated in this question
of mine. So, making a call to the address of the actual sub-routine you wanted to perform. But even though you only had to use this sub into just one location, this lambda expression, you had to fully declare a Private Sub
, and passing the AddressOf
the sub so that the compiler calls it when it is time to do so.
Nevertheless, I know that Microsoft stated she wanted to come up with a fully loaded Visual Basic with the coming of .NET 4.0, making the gap between the two languages thinner and thinner and thinner again so that there is no longer this kind of war "C# is better than VBNET", if you get my point.
Such technical difference was supposed to be corrected in .NET 4.0. I just don't yet know if they did. Anyone knows if they did so?
Hope this helps! =)