C# Faster Than VB?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is C# faster than VB .NET or are they only sepearted by a developers style and coding preference? I understand that all languages are compiled to MSIL so there should be no difference but you never know until you ask!

Cheers, Robby
 
Is C# faster than VB .NET or are they only sepearted by a developers style
and coding preference? I understand that all languages are compiled to
MSIL so there should be no difference but you never know until you ask!

Nothing of any real importance. Due to minor differences in the compilers
its possible that one language may generate better code for a situation than
the other on a given JIT engine, but it shouldn't be noticable, considering
it'll likely be overshadowed by things you can't control, like page faulting
and context switches.
 
In addition to what Daniel said, there'll be no difference if you don't
heavily rely on the VB runtime. Be aware that the VB "native" type cast
operators (CInt) and so on usually invoke method calls that do all sorts of
stuff (unlike a simple C# (cast)).

Also, make sure you have Option Strict On. If you rely on late binding and
such, you'll see things 1000 times slower.

-mike
MVP

Is C# faster than VB .NET or are they only sepearted by a developers style
and coding preference? I understand that all languages are compiled to MSIL
so there should be no difference but you never know until you ask!
 
Thanks for the replies..

So I should DirectCast to an integer instead of using CInt? I'm still considering converting to C# as most professional components are C#... but the one thing I didn't want to loose is the IsDate and IsNumeric functions!

Cheers, Robby
 
Use DirectCast when you just need to cast an object, without any conversion.
For example, if you have a reference to an object type, but you know the
object is actually a string, you can DirectCast the object to a string. Use
CType when you need might need to convert an object from one type to
another.

For example,

Dim x as Integer = Ctype("12345", Integer)

In this example, "12345" is a string, but can be converted to an integer.
You can't use DirectCast with this because a string isn't an integer. When
in doubt, use CType (or CInt, CStr, etc.) instead of DirectCast.

Finally, most VB functions have an equivalent function using .Net Framework
functions. (Most VB functions are actually just wrappers for the Framework
methods.) For example, IsDate corresponds (roughly) to
System.DateTime.Parse. In a pinch, you can use certain VB functions inside
of a C# project by importing the Microsoft.VisualBasic library into your C#
project.

If you're not sure about which language to use, check out this ebook:
http://www.desaware.com/products/books/net/vborc/index.aspx


Thanks for the replies...

So I should DirectCast to an integer instead of using CInt? I'm still
considering converting to C# as most professional components are C#... but
the one thing I didn't want to loose is the IsDate and IsNumeric functions!
 
Everything I've read indicates they're very close.

But even though they both are compiled to MSIL, I've also heard
rumours that some VB.NET code is not compiled to as high-quality MSIL
as C#. I don't know if that's true or not...

My own VB.NET code that I've converted to C# has identical
performance.
 
Back
Top