Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: Visual Basic vs. C#

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Visual Basic vs. C#

    Hi,
    I would like to know which one do you prefer? Why? Is there any difference besides the syntax?

    I know one can do the same, or almost, in both language, have just been wondering this for a while.

    Thanks.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Visual Basic vs. C#

    Found this in Wikipedia, I think it's pretty specific and, apparently, many of the difference between both will be (rather were corrected) "corrected" in 4.0. Anything else?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: Visual Basic vs. C#

    The only genuinely significant difference between the two is that C# supports pointers and VB doesn't. That can make C# code run orders of magnitude faster in specific situations. Those situations are in very much in the minority though. I've never once used unsafe code in C#.

    Other than that, the differences are minor and getting less significant as time goes on. The main point is whether you feel more comfortable with C# syntax or VB syntax. To a large degree that can depend on what you've used before. If you were a VB6 developer then you'll likely feel more comfortable with VB. If you used Java, C++ or any of the many other C-based languages then you'll likely feel more comfortable with C#. That's not the only factor though. I learned to program in C and I worked in C++ for two years before, and I hated VB6, I actually feel slightly more comfortable with VB than C#. It's only marginal though, and I'm happy to work with either and do spend about half my time in each.

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,342

    Re: Visual Basic vs. C#

    Like jmc says the two languages are becoming closer and closer together. If I had continued on learning programming from when I first became interested in it back in 2000 then I would probably still be coding in Visual Basic. Although, being at a technical school that focuses on where business is going with their needs and wants the course was changed to C# instead of VB.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Visual Basic vs. C#

    I actually feel comfortable with both, just wanted to know if there were any significant difference. It appears though, it comes down to personal preference. Guess I'll learn both.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

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

    Re: Visual Basic vs. C#

    I don't really prefer either language, but I do prefer the VB editor in Visual Studio, mainly due to the automatic indenting and stuff. I find that I have to go back and use 'format selection' in C# way more often then in VB (and before I knew about 'format selection' I did it manually!). The C# does have some automatic indenting, but mainly when you type a closing brace or parentheses. In VB, it's pretty hard to actually get it to miss-align something even if you try!


    I do prefer VB's syntax over C# in most of the newer features such as
    Code:
    messageTarget = Function(s) ShowWindowsMessage(s)  'VB
    messageTarget = s => ShowWindowsMessage(s);  // C#
    Not sure why but I feel it's easier to read, as with most of VB since it's much more "wordy" then the minimalistic C#.

    The only thing I dislike about VB's syntax is the Dim statement It looks so ugly! I don't think using C#'s syntax for declaring variables is too minimal, and it would work well for VB too:
    Code:
    String s = "Test"
    Private Integer i = 3
    
    Protected List(Of Integer) numbers = New List(Of Integer) From {1, 2, 3, 4, 5}
    
    ' "modified" For Each
    For Each Integer int In numbers
       MessageBox.Show(int.ToString)
    Next
    
    ' "normal" For Each could still work too, but may be confusing as the order is reversed now suddenly
    For Each int As Integer in numbers
      ...
    Next
    I think it looks ok, better then 'Dim' at least... Ugh.

    What I do like about C# is that it enforces rules such as when the use parentheses much better. In C# for example, when you declare a new instance of a class you must use parentheses:
    Code:
    Button btn = new Button();
    Whereas in VB you can leave them out if you want. I like consistency so I always try to write 'C# style' in VB, using parentheses where it would be required in C# even though I'm using VB.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,583

    Re: Visual Basic vs. C#

    So....you have a dim view of variable declaration in VB?

    There are a couple minor places where the VB syntax appears more clear to me, such as events, but the two are pretty similar. I started in C/C++, so I can read the C syntax pretty well, though I notice that I am getting kind of rusty at it. The thing that mostly bothers me with C is that the typing is so doggone hard to do, but I've flogged that horse in the past, and it is still dead. The point is just that good typists will have an easier time with VB than with C.
    My usual boring signature: Nothing

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

    Re: Visual Basic vs. C#

    Quote Originally Posted by NickThissen View Post
    I don't really prefer either language, but I do prefer the VB editor in Visual Studio, mainly due to the automatic indenting and stuff. I find that I have to go back and use 'format selection' in C# way more often then in VB (and before I knew about 'format selection' I did it manually!). The C# does have some automatic indenting, but mainly when you type a closing brace or parentheses. In VB, it's pretty hard to actually get it to miss-align something even if you try!


    I do prefer VB's syntax over C# in most of the newer features such as
    Code:
    messageTarget = Function(s) ShowWindowsMessage(s)  'VB
    messageTarget = s => ShowWindowsMessage(s);  // C#
    Not sure why but I feel it's easier to read, as with most of VB since it's much more "wordy" then the minimalistic C#.

    The only thing I dislike about VB's syntax is the Dim statement It looks so ugly! I don't think using C#'s syntax for declaring variables is too minimal, and it would work well for VB too:
    Code:
    String s = "Test"
    Private Integer i = 3
    
    Protected List(Of Integer) numbers = New List(Of Integer) From {1, 2, 3, 4, 5}
    
    ' "modified" For Each
    For Each Integer int In numbers
       MessageBox.Show(int.ToString)
    Next
    
    ' "normal" For Each could still work too, but may be confusing as the order is reversed now suddenly
    For Each int As Integer in numbers
      ...
    Next
    I think it looks ok, better then 'Dim' at least... Ugh.

    What I do like about C# is that it enforces rules such as when the use parentheses much better. In C# for example, when you declare a new instance of a class you must use parentheses:
    Code:
    Button btn = new Button();
    Whereas in VB you can leave them out if you want. I like consistency so I always try to write 'C# style' in VB, using parentheses where it would be required in C# even though I'm using VB.
    While I agree with all of this, the one thing I really like about VB is: Private MyClass As New Class, it bugs me that c# makes you type the class twice just to make a new instance of it. That's just a peeve of mine, nothing worth arguing over. The only other thing about c# is the curly braces, they get to be very hard to read since you use them to close everything. Other than those I like c# just as equally as vb.net, though I use vb.net much more often mostly because I came from vb6 and vb6 so...

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Visual Basic vs. C#

    Since I'm studying programming in college reading C code isn't as hard as it used to be, I just wanted to know if there were any differences, apart from those described in Wikipedia, but it seems to come down to personal preference since the discrepancy between both language is almost null.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,342

    Re: Visual Basic vs. C#

    Quote Originally Posted by tassa View Post
    Since I'm studying programming in college reading C code isn't as hard as it used to be, I just wanted to know if there were any differences, apart from those described in Wikipedia, but it seems to come down to personal preference since the discrepancy between both language is almost null.
    Don't you mean c# since that is what the title says? However, I have not use c or c++ so I wouldn't know hard they are too learn. Although, now that I am learning programming and my institute it is not as difficult as I found it to be back when I was using vb6.0.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  11. #11
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Visual Basic vs. C#

    Quote Originally Posted by JuggaloBrotha View Post
    While I agree with all of this, the one thing I really like about VB is: Private MyClass As New Class, it bugs me that c# makes you type the class twice just to make a new instance of it.
    You can always "var" it up, if you would prefer. Let the type of the instance be inferred.

    Gary

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: Visual Basic vs. C#

    Quote Originally Posted by gep13 View Post
    You can always "var" it up, if you would prefer. Let the type of the instance be inferred.

    Gary
    Type inference is valid for local variables only. That said, if you do declare the type of a variable in C# then Intellisense will immediately select that type after you enter the 'new' key word, so the typing isn't a chore.

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

    Re: Visual Basic vs. C#

    Quote Originally Posted by JuggaloBrotha View Post
    While I agree with all of this, the one thing I really like about VB is: Private MyClass As New Class, it bugs me that c# makes you type the class twice just to make a new instance of it.
    I see what you mean, but I actually like C#'s way better, mainly because the 'New' keyboard is easy to miss if you're not carefully reading the code. The difference between
    Code:
    Dim btn As Button
    Dim btn As New Button
    is huge whereas there's only 3 letters difference.

    In C#, the difference is much more obvious
    Code:
    Button btn;
    Button btn = new Button();
    In my opinion, much easier to see quickly whether you're assigning a new instance or not.

    And I do dislike typing the name twice, but you can always use 'var' instead. Also, I'm not sure about this, but I think if you type "Button btn = " then Intellisense will provide you with " new Button()" already. If it doesn't do that then that was probably ReSharper helping me out, but it was useful

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,583

    Re: Visual Basic vs. C#

    Quote Originally Posted by tassa View Post
    ... since the discrepancy between both language is almost null.
    That's the language bias coming through. Had you been studying VB, you would have said that the discrepancy between both languages is almost Nothing.

    MS is trying to merge the features of the two languages, and 2010 with the 4.0 framework was supposed to be a solid step in that direction, but not a final step in that direction. There is yet more convergence to come.
    My usual boring signature: Nothing

  15. #15
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Visual Basic vs. C#

    The important thing that you need to learn is the framework. You need to know what classes you need to use, for instance, to read and write to a text file, you need to become familiar with the classes in the System.IO namespace. Once you know that, the implementation of it is just syntax.

    Gary

  16. #16
    Hyperactive Member storm5510's Avatar
    Join Date
    Jul 2009
    Location
    Indiana, U.S.A.
    Posts
    329

    Re: Visual Basic vs. C#

    I think perhaps many here should try to appreciate what is available now. My programming experiences goes back to late 1987. Things were really "primitive" back then. There were no GUI's and nice development environments.

    One of my class requirements in college was ANSI C. It was intimidating to say the least. All I had was a blank screen with a menu at the top. Afterward, I tried C+, but didn't have a lot of luck with it.

    I've looked at several C# online tutorials and how-to's. Those things were very good and easy to understand. I didn't stick with it because my learning experience was BASIC, QuickBASIC, and onto VB.

    There have been times with I thought BASIC really should be called "ASIC". I don't know if this is still taught now or not, but one of the first things I learned is the meaning of the acronym BASIC: Beginner's All-Purpose Symbolic Instruction Code. If someone has never written any application before, then perhaps it is a "beginners" code, but it has grown way beyond what it meant at the start.

    So, appreciate what you have now! It could be a lot more difficult.

  17. #17
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Visual Basic vs. C#

    I like BASIC/VB/VBA/VB.NET type language more than the C/C++/C#/Java type languages just because you can concentrate more on your programming logic rather than handling the compiler's stupid requirements.

    I heard this too often from my teachers in my childhood:
    "BASIC is a smart language and C is a dumb language. The power of C comes from its dumbness."

    The C compiler though powerful at processing, was awkwardly stupid on the programmer. It was hard to handle.
    Messed up due to case sensitivity
    You missed that () after the function name
    You missed the ; at the end of line
    You missed the } or put it at the wrong place and now you are searching for the culprit.
    Usually the problem was at some line and it reported the problem 100 lines after that. So if you committed a mistake, you had to spend a lot of time debugging it as the exact problem line was seldom pointed out by the compiler.
    Also, in VB the structures were (still are) much more clear and distinct. e.g. End If, End While, Next X etc. distinctly tells you what ends where. While in C if you missed one closing braces, it would take more than an hour to figure out the right place to put it (unless the code is well indented and well commented).

    Now however as the technology advanced and the IDE and compilers got smarter and smarter the difference is reduced way too much to choose one over the other due to any of the reasons I mentioned above. I still like VB over C#, but that's much of a personal preference than due to language differences.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  18. #18
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Visual Basic vs. C#

    Personally, due to the fact that I do a lot of web development, to me it makes much more sense to use C#, because there are a lot of similarities in the code structure when using JavaScript, so you don't have to think in two different mind sets and flip between VB.Net and JS.

    At the end of the day though, it is personal preference. I have got to the point that I am happy to converse in either language, and now concentrate on getting to know the framework, and what it contains.

    Gary

  19. #19
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,342

    Re: Visual Basic vs. C#

    Quote Originally Posted by gep13 View Post
    Personally, due to the fact that I do a lot of web development, to me it makes much more sense to use C#, because there are a lot of similarities in the code structure when using JavaScript, so you don't have to think in two different mind sets and flip between VB.Net and JS.
    That's what I like about C# too! I am glad that we are learning C# because I'm also a web developer (hence my custom title) and would have probably found it confusing trying to get vb.net to work with web stuff.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  20. #20
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Visual Basic vs. C#

    Also go with what you need. I moved away from VB because idustry did (in my area) and as a contractor (or ex contractor) I had to code in what I was told and that was always C#. Never seen any VB in web apps.

  21. #21
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Visual Basic vs. C#

    I like VB.NET's straightforwards names (apart from Dim, which feels natural but makes no sense because, really, couldn't you choose a better word than "dimension"?); C# is sort of strange.
    NotInheritable vs. sealed
    MustInherit vs. abstract

    I also like VB.NET's capitalization, the automatic checking for Nothing/null in event handlers, etc. What bugs me about VB.NET is that you have to put square brackets around GoSub and Let. C# also has a more versatile for loop. VB.NET has a more logical initialization sequence (base class-level initializers, base constructor, class-level initializers, constructor). I can't even remember C#'s. You can also use Declare instead of the longer System.Runtime.InteropServices.DllImport, and you don't have to include "ref" on variables passed by reference (although it does give you a good heads-up).

  22. #22
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Visual Basic vs. C#

    GoSub doesnt exist in VB.net, does it?

    If it does i'm pretty sure you shouldnt be using it

  23. #23
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,342

    Re: Visual Basic vs. C#

    Quote Originally Posted by Pino View Post
    GoSub doesnt exist in VB.net, does it?

    If it does i'm pretty sure you shouldnt be using it
    According to this it does! However, I may have misunderstood what the article is referring to.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  24. #24
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Visual Basic vs. C#

    Name:  gosub-not-supported.JPG
Views: 169
Size:  35.5 KB
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  25. #25
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Visual Basic vs. C#

    Quote Originally Posted by Nightwalker83 View Post
    According to this it does! However, I may have misunderstood what the article is referring to.
    The article was written in 2004, so quite possibly it has become deprecated since.

    Gary

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

    Re: Visual Basic vs. C#

    Quote Originally Posted by minitech View Post
    I like VB.NET's straightforwards names (apart from Dim, which feels natural but makes no sense because, really, couldn't you choose a better word than "dimension"?); C# is sort of strange.
    NotInheritable vs. sealed
    MustInherit vs. abstract
    I do like c/c++/Java/c#'s way of declaring a variable more than vb's, what bugs me is in c# do declare something as an object and create an instance in one line means you have to type out the object's class twice (or use the var and let Infer do it's thing, which I don't like)
    Quote Originally Posted by minitech View Post
    I also like VB.NET's capitalization, the automatic checking for Nothing/null in event handlers, etc. What bugs me about VB.NET is that you have to put square brackets around GoSub and Let. C# also has a more versatile for loop. VB.NET has a more logical initialization sequence (base class-level initializers, base constructor, class-level initializers, constructor). I can't even remember C#'s. You can also use Declare instead of the longer System.Runtime.InteropServices.DllImport, and you don't have to include "ref" on variables passed by reference (although it does give you a good heads-up).
    Things like GoTo, GoSub, Exit... all shouldn't be used and Let hasn't been needed since QBasic (1985) even though they still have it in VB today.

    VB.Net and C# support all of the same loops, so saying C# has a more versatile For loop doesn't make sense, both languages have the For...Next and For Each loops, there isn't any other For loop. Both support the While loop, etc....

    C# and VB.Net default to passing things around ByVal (which is only of use for Integer, Longs, Short, Decimal, Double, Single; Classes passed ByVal have the pointer passed, which is what ByRef does). C# doesn't show anything (that I know of) when something's passed ByVal (VB inserts the keyword for you, unless you specify ByVal/ByRef yourself) and if you want to pass an Integer into a sub by reference then in C# you have to specify it (the ref keyword) yourself.

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

    Re: Visual Basic vs. C#

    Quote Originally Posted by JuggaloBrotha View Post
    C# and VB.Net default to passing things around ByVal (which is only of use for Integer, Longs, Short, Decimal, Double, Single; Classes passed ByVal have the pointer passed, which is what ByRef does). C# doesn't show anything (that I know of) when something's passed ByVal (VB inserts the keyword for you, unless you specify ByVal/ByRef yourself) and if you want to pass an Integer into a sub by reference then in C# you have to specify it (the ref keyword) yourself.
    Or, in other words, C# defaults to passing-by-value, while VB has no default. It's just the editor auto-completing it to ByVal by default, but as far as I know you cannot compile your code if you remove that, so VB really has no default.

  28. #28
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Visual Basic vs. C#

    Quote Originally Posted by NickThissen View Post
    Or, in other words, C# defaults to passing-by-value, while VB has no default. It's just the editor auto-completing it to ByVal by default, but as far as I know you cannot compile your code if you remove that, so VB really has no default.
    I removed the "ByVal" and compiled and it compiles ok.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  29. #29

  30. #30
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Visual Basic vs. C#

    I've always pictured programming languages in "Levels".

    Assembler is pretty much as low as it gets - Machine Code with mnemonics.

    I think of C (in the old days) as a Medium level language. Human readable language but still quite close to the hardware so you needed to understand your hardware and clean up your own mess when you're done.

    Then Basic (in the old days) is a high level language. Very human readable and not much requirement to know much about the hardware because you didn't have much access to hardware anyway. The only way to get near the hardware was to go down a level to something like C.

    I mentioned "In the old days" because things have changed and Basic (which was once considered to be a "Beginner's All Purpose Symbolic Instruction Code" has gotten very powerfull so we can do pretty much anything we want with VisualBasic (Don't let then C nerds tell you otherwise) and we don't really need lower level languages anymore.

    C# ? It's a high level language just like Basic - I once heard it referred to as Basic with "SemiColons".

    I'd say it's "Visual Basic for C nerds"

    If you're a C nerd please don't be offended - I'm one too.
    Last edited by IanS; Jun 14th, 2010 at 09:57 AM.

  31. #31
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Visual Basic vs. C#

    Quote Originally Posted by NickThissen View Post
    And it didn't secretly add it back without you seeing? In my experience it will add it back whenever it gets the change... Strange. I thought it was a requirement.
    No. I confirmed twice before posting here.

    Also from what I have read from books, this is one of the differences between VB6 and VB.NET. The ByVal is default in VB.NET while ByRef was default in VB6 and earlier.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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

    Re: Visual Basic vs. C#

    Quote Originally Posted by NickThissen View Post
    Or, in other words, C# defaults to passing-by-value, while VB has no default. It's just the editor auto-completing it to ByVal by default, but as far as I know you cannot compile your code if you remove that, so VB really has no default.
    Yea, when you type something like Private Sub YourSub (YourParam As Type) then press enter it'll insert the "ByVal" for all of the params that don't already have ByVal/ByRef typed in. You know that already..
    Quote Originally Posted by IanS View Post
    I've always pictured programming languages in "Levels".

    Assembler is pretty much as low as it gets - Machine Code with mnemonics.

    I think of C (in the old days) as a Medium level language. Human readable language but still quite close to the hardware so you needed to understand your hardware and clean up your own mess when you're done.

    Then Basic (in the old days) is a high level language. Very human readable and not much requirement to know much about the hardware because you didn't have much access to hardware anyway. The only way to get near the hardware was to go down a level to something like C.

    I mentioned "In the old days" because things have changed and Basic (which was once considered to be a "Beginner's All Purpose Symbolic Instruction Code" has gotten very powerfull so we can do pretty much anything we want with VisualBasic (Don't let then C nerds tell you otherwise) and we don't really need lower level languages anymore.

    C# ? It's a high level language just like Basic - I once heard it referred to as Basic with "SemiColons".

    I'd say it's "Visual Basic for C nerds"

    If you're a C nerd please don't be offended - I'm one too.
    C# can use pointers directly, which vb.net cannot do. So I guess one could say c# is a little lower level than vb still, but it's all a moot point.

  33. #33
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Visual Basic vs. C#

    Quote Originally Posted by JuggaloBrotha View Post
    Yea, when you type something like Private Sub YourSub (YourParam As Type) then press enter it'll insert the "ByVal" for all of the params that don't already have ByVal/ByRef typed in. You know that already..
    After pressing Enter, if you don't like the changes made by the IDE automatically, press CTRL+Z immediately after that and the changes will revert back.

    So doing the above, and removing all "ByVal" I see that it compiles good. Also ByVal is assumed by default, when nothing is not specified.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  34. #34
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Visual Basic vs. C#

    GoSub and Let don't do anything, but you can't use them as property/method names without brackets.

  35. #35
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Visual Basic vs. C#

    Quote Originally Posted by JuggaloBrotha View Post
    C# can use pointers directly, which vb.net cannot do. So I guess one could say c# is a little lower level than vb still, but it's all a moot point.
    Microsoft's c# 2005 Step by Step by John Sharp has a page or so about pointers in c and c++ explaining how they're used and the kind of problems they can cause if not used correctly.

    It then goes on to say:-

    Code:
    Reference Variables were added to c# to avoid all these problems.
    If you really want to, you can continue to use pointers in c# but you must
    mark your code as unsafe.
    
    It then shows a couple of examples of using the unsafe keyword.
    
    It then goes on to say ... unsafe code has a bearing on how memory is managed:
    objects created in unsafe code are said to be 'Unmanaged'.
    So I reckon what that is saying is that c# 'can' use pointers in similar syntax to c/c++ but you really shouldn't. You should use the same 'reference variables' just like you'd do in VB
    Last edited by IanS; Jun 14th, 2010 at 05:27 PM.

  36. #36
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,342

    Re: Visual Basic vs. C#

    Quote Originally Posted by gep13 View Post
    The article was written in 2004, so quite possibly it has become deprecated since.

    Gary
    Ah, I missed that.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  37. #37
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Visual Basic vs. C#

    Quote Originally Posted by IanS View Post
    Microsoft's c# 2005 Step by Step by John Sharp has a page or so about pointers in c and c++ explaining how they're used and the kind of problems they can cause if not used correctly.

    It then goes on to say:-

    Code:
    Reference Variables were added to c# to avoid all these problems.
    If you really want to, you can continue to use pointers in c# but you must
    mark your code as unsafe.
    
    It then shows a couple of examples of using the unsafe keyword.
    
    It then goes on to say ... unsafe code has a bearing on how memory is managed:
    objects created in unsafe code are said to be 'Unmanaged'.
    So I reckon what that is saying is that c# 'can' use pointers in similar syntax to c/c++ but you really shouldn't. You should use the same 'reference variables' just like you'd do in VB
    Unmanaged code is not a bad thing, ever done any heavy graphic manipulation? If you didnt use "unsafe" code then it would be painful.

  38. #38
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Visual Basic vs. C#

    That's what LockBits is for. And you can use graphic APIs, too.

    (Well, I guess there's a problem there, too: in my Vista Forms, the thing that's taking the longest is actually locking the bits of the image in the first place.)

  39. #39
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Visual Basic vs. C#

    Lockbits is unmanaged, unsafe code!

  40. #40
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Visual Basic vs. C#

    In a managed wrapper, though. 100% safe.

Page 1 of 2 12 LastLast

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