none
Difference between C# and VB.NET

    Question

  • I am a VB.NET developer, and I was wondering if there is really any need to switch to C# to gain more power in my applications. I would like the main difference between them. For example:

    • If you really gain more power with C#
    • Writing shorter code

    Thanks, suggestions or answers would be apreciated...


    Weston

    Saturday, August 31, 2013 9:18 PM

Answers

All replies

  • http://www.codeproject.com/Articles/9978/Complete-Comparison-for-VB-NET-and-C


    Musakkhir Sayyed.

    Saturday, August 31, 2013 9:21 PM
  • That article was from 2005, It would be nice if there was a more recent comparison. More features have been added, and things can change.

    Weston

    Saturday, August 31, 2013 9:25 PM
  • I think no difference because two language is intermediate language and use same framework to interpreter to machine language but difference may by support for c# is more than VB because. 
    • Marked as answer by westprogram1 Saturday, August 31, 2013 10:09 PM
    Saturday, August 31, 2013 9:25 PM
  • So both have all or almost all the same capabilities, but different languages. Correct?

    Weston

    Saturday, August 31, 2013 9:27 PM
  • There's been plenty written about that already, e.g. http://social.msdn.microsoft.com/Forums/vstudio/en-US/0250c3cf-092e-4afc-899b-308c04695cea/vbnet-versus-c (from 2012, so quite recent).

    What might be of more value to you as a programmer would be learning a completely different language. Perhaps a functional language like F# or LISP. Then you would be likely to have a better-trained sense of how to approach a problem in different ways.

    --

    Andrew

    • Marked as answer by westprogram1 Saturday, August 31, 2013 10:09 PM
    Saturday, August 31, 2013 9:59 PM
  • So both have all or almost all the same capabilities, but different languages. Correct?

    Weston

    correct
    Saturday, August 31, 2013 10:03 PM
  • The main difference between VB and C#.NET is with the developer in architecting solutions.

    The VB developer doesn't know about the topics in the link as opposed to C# developers that know it or have a good knowledge of it. 

    http://www.dofactory.com/framework/framework.aspx

    Being a coder monkey is one thing, but they pay the big dollars if one knows how to architect solutions.

    Saturday, August 31, 2013 10:17 PM
  • My 2 cents:

    In the latest version of VB.Net, a well written VB program compiles to almost identical IL code as a well written C# program.  This wasn't the case with VB.Net 2002 and 2003.  There are a few small differences in the two languages: http://msdn.microsoft.com/en-us/library/czz35az4(v=vs.100).aspx

    In the real world, C# programmers tend to make more money because most C# programmers came from C++ which is an object oriented language.  Most vb.net programmers started with vb6 which is not an object oriented language. As time goes on, this will go away, since new programmers start with one of object oriented languages in .Net.

    I have coded in both C# and VB.Net and I prefer VB.Net simply because the braces drive me blind.


    The difference between genius and stupidity is that genius has its limits.

    Saturday, August 31, 2013 11:24 PM
  • I found this difference:

    I'll appreciate if someone can explain me the cause... :-)

    Friday, May 02, 2014 4:13 PM
  • There's been plenty written about that already, e.g. http://social.msdn.microsoft.com/Forums/vstudio/en-US/0250c3cf-092e-4afc-899b-308c04695cea/vbnet-versus-c (from 2012, so quite recent).

    What might be of more value to you as a programmer would be learning a completely different language. Perhaps a functional language like F# or LISP. Then you would be likely to have a better-trained sense of how to approach a problem in different ways.

    --

    Andrew

    In my perception the thread is wrong. Rudy has very few knowledge about VB but still gives his opinion. 

    You can use endless namespaces in VB.


    Success
    Cor

    Friday, May 02, 2014 4:39 PM
  • Yes there are many differences, but not in the way this thread is asked about the power. Therefore the marked answers in this thread are strange. It is probably done by a biased C# person.

    You gain no power by switching from C# to VB or vice vers only more simplicity in coding in the way which you prefer.

    VB has default values for value types and strings.

    "Nothing" has in VB therefore 2 meanings:

    1. It is the default value for value types (and also for strings)
    2. For an reference type it means "nothing set in the reference address

    In C# it means in fact only nothing in the reference address

    Therefore those differences. 


    Success
    Cor



    Friday, May 02, 2014 4:46 PM
  • I found this difference:

    I'll appreciate if someone can explain me the cause... :-)

    In VB, use Option Strict On ...And the compiler will tell you why. 

    Your code in VB is actually very wrong base on what you are expecting it to do

    ;)

    Friday, May 02, 2014 5:22 PM
  • Luc,

    I see no problem. The default value for a string is "" in VB and therefore they are of course the same.


    Success
    Cor

    Friday, May 02, 2014 6:05 PM
  • I found this difference: ...

    I'll appreciate if someone can explain me the cause... :-)

    In VB, use Is Nothing to compare to Nothing (IsNot is also available), e.g.

    Dim s1 As String = Nothing
    Dim s3 As String = ""
    
    If s1 Is Nothing Then Console.WriteLine("Is Nothing") Else Console.WriteLine("Is something.")
    If s3 Is Nothing Then Console.WriteLine("Is Nothing") Else Console.WriteLine("Is something.")
    

    Outputs:

    Is Nothing
    Is something.
    --

    Andrew

    Friday, May 02, 2014 6:28 PM
  • Also note that you've assumed that "null" and "Nothing" are the same thing, and they are not.  The VB keyword "Nothing" is more equivalent to C#'s Default<T>. 

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, May 02, 2014 7:01 PM
  • I discover the answer seeing the IL with ILDAsm.

    C# == becomes string.Equals(Str1, Str2);

    VB =  becomes Str1.CompareTo(Str2)

    In VB you can write also

    Str1 Is Str2

    The result is the same in C#

    Tuesday, May 20, 2014 11:33 AM
  • They have identical speeds BUT C# has unsafe code which VB does not have.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Tuesday, May 20, 2014 2:37 PM
  • Hello,

    Bottom line, if you are just starting out I recommend C# because of the market place is asking for C#. Which is easier to learn, it's a tossup, all depends on your brain. Personally I see VB.NET easier to read and (at least for me) slightly faster to write code.

    If we compare two language extension methods between C# and VB.NET there is little difference

    C#

    public static T FieldLastValue<T>(this DataTable dt, int ColumnIndex)
    {
        return dt.Rows[dt.Rows.Count - 1].Field<T>(dt.Columns[ColumnIndex]);
    }

    VB.NET

    <System.Runtime.CompilerServices.Extension()> _
    Public Function FieldLastValue(Of T)(ByVal dt As DataTable, ByVal ColumnIndex As Integer) As T
        Return dt.Rows.Item(dt.Row.Count -1).Field(Of T)(dt.Columns(ColumnIndex))
    End Function

    Another example, casting, still not much difference but one thing to point out, C# in any example of VB.NET is case sensitive.

    C#

    decimal ManufacturerIdentifier =
        (
            (DataRowView)cboManufacturers.SelectedItem
        ).Row.Field<int>("Indentifer");

    VB.NET

    Dim ManufacturerIdentifier As Decimal = CType(cboManufacturers.SelectedItem, DataRowView).Row.Field(Of Integer)("Indentifer")

    When wiring up events VB.NET makes it easy in a visual way to setup events while C# lacks the visual aspect which at first glance can be furustrating yet using this method it's not so bad.

    If you would like to see a overall difference in how C# and VB.NET compare in how things are done see this page.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, May 20, 2014 3:52 PM
  • In C#, you can access low-level (unsafe) code, which is not available in VB (100% safe).  This may be the most important difference, and the more experienced programmers coming from C or C++ can take advantage of it.

    There are a couple of things in VB not available in C#. For example:

    InputBox
    Static variables

    You can make C# do something like it but with a lot more code and not as simply.

    Solitaire

    Tuesday, May 20, 2014 4:38 PM
  • @Solitair

    Maybe you did not see it, but this thread is a death horse from 2013 there are many more differences, but like you wrote, with both languages you can do the same. Mostly these discussions start with C# persons who want to proof that they don't understand VB. Most trained VB programmers do know both languages.

    Like Kevin already wrote, is C# also in my opinion easier to learn, but slower when writing code.


    Success
    Cor

    Tuesday, May 20, 2014 4:49 PM
  • They have identical speeds BUT C# has unsafe code which VB does not have.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me


    This isn't entirely correct.  C# has an "unsafe" keyword which VB does not have; there are a number of keyword differences between the languages like C# has no "My" keyword.  You can still write unmanaged code in VB just like you can still access resources and application info in C#; you just have to go about it differently.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 20, 2014 7:50 PM
  • Reed would you expand on your assertion that you may write unmanaged code in VB.net. That's a new one.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Tuesday, May 20, 2014 9:02 PM
  • Reed would you expand on your assertion that you may write unmanaged code in VB.net. That's a new one.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me


    I should have worded that differently; you can still write code that manipulates unmanaged memory - its always managed code in a managed environment.  You are correct that VB has no unmanaged pointer like C#, so in C# you can write managed code which will execute in an unsafe context.  I guess I just wanted to point out that it was a keyword and only applied to certain scenarios.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 20, 2014 9:52 PM
  • Note:  Unless I'm mistaken, the C# equivalent of the VB "My" keyword is "this"

    Solitaire

    Wednesday, May 21, 2014 2:47 AM
  • Solitaire,

    the equivalent of C# "this" is VB "Me".

    "My" also isn`t a keyword in VB but a Namespace


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    My Forum Threads

    Wednesday, May 21, 2014 7:46 AM
  • Thanks for the heads-up.

    Solitaire

    Thursday, May 22, 2014 12:08 AM