Results 1 to 27 of 27

Thread: Visual Basic vs. C Sharp

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    Visual Basic vs. C Sharp

    Hi Guys,
    I've been thinking of doing my next project in C Sharp. When I loaded it up the interface for C Sharp looked just like Visual Basic. The only difference was the syntax was different. So I was wondering is there any benefits for using C Sharp over Visual Basic. What types of programs would benefit from being written in Visual Basic or C Sharp?

    I'm not trying to start a language war. I'm just wondering if there is anything to gain from writing in either language.
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Visual Basic vs. C Sharp

    There are only a very small set of features in C# that are not available in VB, and the same is true for VB's feature set compared to C#.

    VB has things like XML literals, and C# has things like unsafe code and iterators.

    There are a few others, and I am sure there are detailed comparisons of the differences if you search the web.

    One thing that has changed at Microsoft somewhat recently, is that the dev teams have been realigned to co-evolve both these top languages that MS has, so that features will be added in parity, instead of this feature being given to C# and that feature being given to VB. VS2010 is a good example of this, as many new features to C# are things VB had for a long time, and VB is getting some features C# has had for a while now. Yet still, some new features are being added to the languages at the same time for this next release.

    There is a little bit of reality here though, which is that:

    Of the 2, C# is the dominant language within Microsoft itself. C# was used to create much of the VS IDE. Most examples you will find will either be in C# only, or C# and VB. Especially from Microsoft. You don't find too many examples that are VB only these days. VB has been around a long time, and before .NET it was lacking many features of a true OO language. Because of this, VB was long labeled a toy language not for professional use, which is totally false, but this is how lots of people (who don't use VB) look at it. So even though VB and C# are pretty much the same in capabilities now, lots of C style coders still stick their nose up at VB.

    Other than that, there is no harm in learning C# syntax. If anything it will just make you better at learning multiple languages and being able to go back and forth. It will also help you to be able to look at a block of C# code, and type it out in VB, or vice versa.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Visual Basic vs. C Sharp

    Moved to General Developer

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Visual Basic vs. C Sharp

    The two groups were separate within MS, which lead to a divergence between the two languages. This divergence is being corrected, and the languages are coming back together, in my understanding. I think it is easier to use events in VB, and unmanaged code via pointers in C#, but the two are virtually interchangeable.
    My usual boring signature: Nothing

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Visual Basic vs. C Sharp

    "I'm not trying to start a language war." -- too, late... it's been started... just kidding... it's just that question will bring out the advocates of both camps.

    "I'm just wondering if there is anything to gain from writing in either language." - virtually none.... there are a few things that C# can do, that can't be done in VB, but then VB has a few things that C# doesn't. since both are built on .NET framework.... they are virtually identical. It comes down to which language you are more comfortable with. VB tends to be considerable more verbose in its construct, but if curly brackets and semi colons confuse you, C# will seem cryptic.

    what I've seen over the last few releases, and even with the up comming one from VS2010, VB will add a feature, the C# team goes "Oooh, that's cool" and adds it to the next version.... along with other things. The VB Team then sees that new feature and goes "Oooh, that's cool" .... and adds it to their next release.... and so the cycle continues...

    One of the biggest things that C# can do that VB can't (yet) is to run inline unmanaged code... that is code that runs in it's own space and isn't part of the managed framework - like ASM or even unmanaged C/C++ code.... if you've got a graphics package that is doing a lot of calculations, this is a good thing.... IF you know what you are doing. If it's not something you need... then never mind it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by techgnome View Post
    One of the biggest things that C# can do that VB can't (yet) is to run inline unmanaged code... that is code that runs in it's own space and isn't part of the managed framework - like ASM or even unmanaged C/C++ code.... if you've got a graphics package that is doing a lot of calculations, this is a good thing.... IF you know what you are doing. If it's not something you need... then never mind it.

    -tg
    Just to expand on this a bit, there is also nothing stopping you from doing something like writing a DLL in C# that does some stuff that only C# can do, and reference this DLL from a VB application and use the C# function inside it from your VB code. It could even be F# or any other .NET language..

    So solutions can be made up of combinations of C# and VB and any other .NET language.

    Projects need to be a specific language, but solutions are just groups of projects.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    Re: Visual Basic vs. C Sharp

    I did notice one thing that was nice about C sharp that isn't so nice in visual basic. That is the multiple line comments. Visual Basic does have these and sometimes it gets in the way.
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Visual Basic vs. C Sharp

    yeah... that's a bit of a bunger isn't it... I wish VB had better support for multi line commenting. What I do in that case is jsut write out the comments over the multi lines, then highlight the block and use Ctrl+K,Ctrl+C to comment the whole block.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Visual Basic vs. C Sharp

    Learn both; program in the one you are comfortable with.

    Personally, I find the prolific use of curly braces and semi-colons detrimental to my eyes, so program in VB. If I have a need for features that C# offers which are not available in VB, then it's a simple matter of creating a C# DLL, for example. I've not come across any case where VB simply cannot do something that C# can, however.

    I'm not sure that the 'comments' difference is a basis to choose a language, but for the lack of anything substantial, I suppose it's as good a reason as any
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  10. #10
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Visual Basic vs. C Sharp

    I've also noticed, while no fault of the language itself, that the Visual Studio development environment seems to behave nicer when working with VB.NET as opposed to C#. It just seems to behave "smarter" when working with VB.NET.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  11. #11
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Visual Basic vs. C Sharp

    I find the VB.Net IDE to be much more intuitive than c#.

    Here's an example, creating a sub to handle an event in the code behind window, I don't understand why c# couldn't have the objects on the form (win or web, doesn't matter) in one dropdown and when you select the control the other drop down has the events in which you select the event and if it doesn't already exist, then the IDE creates the code block (and adds the AddHandler call) automatically.

    Granted it's just generating an empty sub, but I never need MSDN open to lookup event parameters when programming in vb.net, I always have it open when working in c#.

    And what's with c#'s switch statement being so limited compared to vb.net's Select Case statement anyways?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  12. #12
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Visual Basic vs. C Sharp

    I just spotted this in Tom Sawyer's sig: "(VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>."

    Anyways, one of VB's idiosyncrasies is going away in the next version - the line continuation character. More appropriately it is going to be optional. No longer will we need to do this:
    Code:
    Private sub SomeErrorHandler( sender as Object, _
         e As SystemEventArgs)
    We'll be able to do this:
    Code:
    Private sub SomeErrorHandler( sender as Object, 
         e As SystemEventArgs)
    And (gawd forbid) this:
    Code:
    Dim myWoefullyLongSQL As String = "Select some_really_Trivial_Item " &
         "From some_Other_Trivial_Table T" & 
         "INNER JOIN Another_Trivial_Table T1 ON T.SomeField = T2.YAF"
    When I asked about it, I was told they hit what they believe to be 95&#37; of the cases... in other words, if it's obvious there's something on the next line (because you ended the last one with a comma, or an ampersand or something else).... then it'll pick it up.... what won't fly is this:

    Code:
    Private sub SomeErrorHandler( sender as Object
         , e As SystemEventArgs)
    
    Dim myWoefullyLongSQL As String = "Select some_really_Trivial_Item "
         & "From some_Other_Trivial_Table T"
         & "INNER JOIN Another_Trivial_Table T1 ON T.SomeField = T2.YAF"
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Visual Basic vs. C Sharp

    Still true today: http://www.vbforums.com/showthread.php?t=539686

    You should know both if you can manage it. Simply because it is very frustrating to not be able to read examples written in one or the other. Also the more you learn the .NET framework and its classes etc the more trivial the differences become!

  14. #14
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Talking Re: Visual Basic vs. C Sharp

    If you code in C# with others you are one day going to see this on your screen:

    Code:
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    The biggest flock of seagulls I have seen so far was 10. Any better?

  15. #15
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Visual Basic vs. C Sharp

    No better but they do end up EVERYWHERE! take a look!

    CSharp Code:
    1. private void PopulateList(String SourceType, String OutputType)
    2.         {
    3.             //Populate The ListOfSubRules Property using LINQ to XML
    4.             var XMLSubRules = from XMLSubRule
    5.                               in XDocument.Load("DataStore.xml").Descendants("SubRule")
    6.                               where (XMLSubRule.Attribute("SourceType").Value == SourceType && XMLSubRule.Attribute("OutputType").Value == OutputType)
    7.                               select new
    8.                               {
    9.                                   Expression = XMLSubRule.Element("Expression").Value,
    10.                                   IsMatchExpression = XMLSubRule.Element("IsMatchExpression").Value,
    11.                                   OpeningElement = XMLSubRule.Element("OpeningElement").Value,
    12.                                   ClosingElement = XMLSubRule.Element("ClosingElement").Value
    13.                               };
    14.  
    15.             foreach (var XMLSubRule in XMLSubRules)
    16.             {
    17.                 ListOfSubRules.Add(new SubRule(XMLSubRule.Expression,
    18.                                                XMLSubRule.IsMatchExpression,
    19.                                                XMLSubRule.OpeningElement,
    20.                                                XMLSubRule.ClosingElement));
    21.             }
    22.  
    23.  
    24.  
    25.         }
    26.  
    27.         private void GetCommentCode(String SourceType, String OutputType)
    28.         {
    29.             var CommentFromXML = from XMLComment
    30.                                  in XDocument.Load("DataStore.xml").Descendants("Comments")
    31.                                  where (XMLComment.Attribute("SourceType").Value == SourceType && XMLComment.Attribute("OutputType").Value == OutputType)
    32.                                  select new
    33.                                  {
    34.                                      Expression = XMLComment.Element("Expression").Value,
    35.                                      OpeningElement = XMLComment.Element("OpeningElement").Value,
    36.                                      ClosingElement = XMLComment.Element("ClosingElement").Value
    37.                                  };
    38.         }
    39.  
    40.  
    41.         private void CreateMasterExpression()
    42.         {
    43.             String RawMasterExpressionString = String.Empty;
    44.             foreach (SubRule SubRuleItem in ListOfSubRules)
    45.             {
    46.                 const string AndOrSymbol = "|";
    47.                 RawMasterExpressionString = RawMasterExpressionString + AndOrSymbol + SubRuleItem.Expression;
    48.             }
    49.  
    50.             // Removes the first OR from the string otherwise it will error.
    51.             MasterExpression = RawMasterExpressionString.Remove(0,1);
    52.         }
    53.     }
    54. }

  16. #16
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Visual Basic vs. C Sharp

    I have always noticed that the code editor for C# is not as good as the one for VB... The VB editor handles smart formatting better (I think that's what it is).. For example, if you have the following code in C#:
    Code:
            private void Form1_Load(object sender, EventArgs e)
            {
                if (3 == 2)
                {
                    MessageBox.Show("Huh?");
                    MessageBox.Show("That doesn't make sense...");
                }
            }
    And you then try to delete the second Messagebox call, ending up with a blank line:
    Code:
            private void Form1_Load(object sender, EventArgs e)
            {
                if (3 == 2)
                {
                    MessageBox.Show("Huh?");
                    
                }
            }
    Finally, you want to delete the blank line, and voila:
    Code:
            private void Form1_Load(object sender, EventArgs e)
            {
                if (3 == 2)
                {
                    MessageBox.Show("Huh?");
                                }
            }
    The brace isn't formatted correctly.


    Try the same thing in VB and it does format it!
    Just a stupid example, I know, but I have found it can get very annoying at times...

  17. #17
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Visual Basic vs. C Sharp

    Does anyone know if the equals operator is going to be overloaded in c# like it is in vb?

    What I mean is in c# will be be able to do this:
    Code:
    if (SomeVar = SomeValue)
    Instead of:
    Code:
    if (SomeVar == SomeValue)
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  18. #18
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Visual Basic vs. C Sharp

    I heard a joke once: What's the difference between C# and VB?
    A: About 8 grand a year

    OK, so it's not particularly funny but it does highlight a point. The differences being highlighted in this thread are pretty trivial and mostly revolve around the usability of the editor and readability of the syntax rather than the features which are available. Post the same question on a C# forum and I'm willing to bet you'd get devs saying that C# is more readable and the IDE is superior - it's just what we're used to.

    Klienma hit on what is the major difference as I see it. VB.Net tended to get adopted by old VB6 devs while C# tended to get adopted by old C/C++ and Java devs. That means that the work available in the two languages has a tendancy to be different too. E.g. Enterprise apps tend to be developed in C# while small business apps tend to be in VB. As a consequence C# tends to be better paid.

    Note the use of the word 'Tends' though. We're nearly a decade down on now and the line's increasingly blurred. I will say, though, if my recent job hunt (about 6 months ago) was anything to go by, it's still there. If you're asking because you want to pursue a career in one or the other I'd say this is a far more important consideration than whether or not you're irritated by curly brackets.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  19. #19
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by JuggaloBrotha View Post
    Does anyone know if the equals operator is going to be overloaded in c# like it is in vb?

    What I mean is in c# will be be able to do this:
    Code:
    if (SomeVar = SomeValue)
    Instead of:
    Code:
    if (SomeVar == SomeValue)
    No.... the first one is an assignment operator.... the second is a comparison operator. Since C# is loosely based on C, I don't expect that to change ever.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by techgnome View Post
    No.... the first one is an assignment operator.... the second is a comparison operator. Since C# is loosely based on C, I don't expect that to change ever.

    -tg
    I figure as much, but it never hurts to ask.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  21. #21
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by JuggaloBrotha View Post
    Does anyone know if the equals operator is going to be overloaded in c# like it is in vb?

    What I mean is in c# will be be able to do this:
    Code:
    if (SomeVar = SomeValue)
    Instead of:
    Code:
    if (SomeVar == SomeValue)
    This is (for me, anyway) one of the big problems when switching between C# and VB. I've spent many an hour trying to figure out why a piece of simple code isn't working to find out that an assignment is being made instead of a comparison....urk...
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  22. #22
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Visual Basic vs. C Sharp

    Get squiggles and coderush express and all those errors will be known to you at compile time.

  23. #23
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by techgnome View Post
    No.... the first one is an assignment operator.... the second is a comparison operator. Since C# is loosely based on C, I don't expect that to change ever.

    -tg
    Yeah ... the function of those two is so fundamental to the language (any C-type language) that to change it would cause major problems.

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  24. #24
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Visual Basic vs. C Sharp

    Quote Originally Posted by DeanMc View Post
    Get squiggles and coderush express and all those errors will be known to you at compile time.
    What errors?
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  25. #25
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Visual Basic vs. C Sharp

    I'm not saying they should overload the equals operator and drop the comparison operator altogether, just make it so you could use either methods for comparison, IE:
    Code:
    if (SomeVar = SomeValue)
    and
    Code:
    if (SomeVar == SomeValue)
    both do the same thing

    As for the compile errors showing at design time, I really like how they gave c# a partial background compiler in VS 2008, it could be better but it's still better having the partial one.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  26. #26
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Visual Basic vs. C Sharp

    The problem is that they were orinally separated out for a reson. It allowed C coders, who tend to be a bit anal about typing as few characters as possible, to do things like this:-
    Code:
    If (x=1==y)
    That will set the value of x to 1 and then return true if y is 1. Code like that already exists and is out there in use. If you make them interchangable you'll break existing code.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  27. #27
    Hyperactive Member rplcmint's Avatar
    Join Date
    Jan 2001
    Location
    Stockton, CA
    Posts
    333

    Re: Visual Basic vs. C Sharp

    Cool discussion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width