Static Wikipedia February 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Web Analytics
Cookie Policy Terms and Conditions Comparison of C sharp and Visual Basic .NET - Wikipedia, the free encyclopedia

Comparison of C sharp and Visual Basic .NET

From Wikipedia, the free encyclopedia

The correct title of this article is Comparison of C# and Visual Basic .NET. The substitution or omission of a # sign is because of technical restrictions.
This article is part of
the Programming Language Comparison
series.
General Comparison
Basic Syntax
String Operations
String Functions

Evaluation strategy
List of "hello world" programs

Compatibility of C and C++
Comparison of C and Pascal
Comparison of C++ and Java
Comparison of C# and Java
Comparison of C# and Visual Basic .NET


The original .NET Framework distributions from Microsoft included several language-to-IL compilers, including the two primary languages: C# and Visual Basic. There is heated debate among the greater .NET community about which language is better in general, or for specific purposes. It has also become a common homework question for students. Below is a comparison of the two languages.

Contents

[edit] Compatibility

It should be noted that all .NET programming languages share the same runtime engine, and when compiled produced binaries that are seamlessly compatible with other .NET programming languages, including cross language inheritance, exception handling, and debugging.

[edit] No second class languages

One of the main selling points of .NET has been its multi language support, and the concept of "no second class languages". That is, all of the various Microsoft languages should have the same level of access to all OS features, and all expose the same level of power and usability.

Visual Basic has been significantly updated from its VB1-6 days. Older versions of VB were object-based, that is to say not fully object-oriented, had limited access to API functions through COM, and had many other limitations. In .NET, most of these limitations have been removed, with minimal impact on the language's syntax and structure. VB.NET is fully object-oriented, and has full access to the .NET framework. C# has taken concepts from other languages, notably Java and Delphi, combined with a syntax similar to C and Java.

[edit] Culture

While there are some technical differences between the languages (detailed below), there are also many differences in the cultures of the developers who use them. Many .NET developers came from either the VB environment, or the C/C++ environment[citation needed]. These two groups had very different coding standards, best practices, etc. Many of these paradigms came from language or IDE features. While the historical reasons for these practices are no longer applicable in all cases, the culture differences remain.

[edit] Visual Basic .NET culture

VB historically was a RAD tool, as well as a tool that was usable by untrained developers, or management. As a result of this wider user base, VB allowed for many shortcuts and ease of use features. These features allowed for the uninitiated to create code, but also contributed to maintenance and debugging issues. Examples of the shortcuts allowed in VB

  • Optional declaration of variables
  • Optional Weak Typing using late binding
  • Optional Parameters

[edit] C# culture

C# developers tend to be prior C/C++ developers, or Java developers. C# is syntactically very similar to C and Java, the IDEs and command line tools work very similarly, and the culture is the same. Also, C# inherited quite a bit of its style and culture from the Delphi/Object Pascal programming language.

[edit] Language features

The bulk of the differences between C# and VB.NET from a technical perspective are syntactic sugar. That is, most of the features are in both languages, but some things are easier to do in one language than another. Many of the differences between the two languages are actually centred around the IDE.

[edit] Features common to all C# and VB.Net

These features are common to both C# and VB.Net. Some of these features may be available in other .Net languages as well.

  • Garbage collection
  • Object oriented
  • Reflection support
  • Generics
  • Operator Overloading

[edit] Features of C# not found in Visual Basic .NET

  • Supports unsafe code blocks for improved performance at the expense of not being verifiable as "safe" by the runtime
  • Anonymous methods
  • Nullable structures are supported with the ? notation
  • Iterators
  • Multi-line comments (although this is accomplished in VB with the 'block comment' button.)
  • Static classes (Classes which cannot contain any non-static members, although VB's Modules are essentially sealed static classes with additional semantics)

[edit] Features of Visual Basic .NET not found in C#

  • With keyword for using the same object repeatedly (this feature was intentionally not added to C# [1])
  • Named indexers (essentially, properties that take arguments)
  • The My namespace, which simplifies the use of many framework classes by encapsulating their functionality in a flatter, more accessible structure
  • More granularity with exception handling with the CatchWhen clause, which allows for custom exception filters
  • The Handles keyword allows declarative wiring of events to functions; Imperative (C# style) event wiring is also available.
  • Optionally ignore ref/ByRef behavior for passing arguments. (C# requires a temp variable to do this.)
  • Optional parameter support is useful when using COM automation. This is especially important when working with Microsoft Office.
  • VB Select Case (switch statements) allow for ranges and even mathimatical operations on each condition.
  • The MyClass keyword which performs a non-virtual method call on an overridden method

[edit] Criticisms of Visual Basic .NET not applicable to C#

VB.NETs supports several syntactic "shortcuts", which exist mostly due to the language's legacy support. While these can be valuable in some circumstances, they are also often a significant source of errors and headaches.

  • Optional variable declaration
  • Optional strong typing

[edit] Criticisms of C# not applicable to Visual Basic .NET

  • By default, numeric operations are not checked. This results in slightly faster code, at the risk that numeric overflows will not be detected.

[edit] Syntax Comparisons

[edit] Comments

C# Visual Basic .NET
// Single Line Comment ' Single Line Comment
/* Multi-line

comment */

N/A
/// XML Comments ''' XML Comments

[edit] if-then-else

C# Visual Basic .NET
 if (condition)
 { 
   // condition is true  
 }
 If condition Then 
   'condition is true
 End If
 if (condition)
 { 
   // condition is true 
 }
 else
 { 
   // condition is false 
 }
 If condition Then 
   'condition is true
 Else
   'condition is false
 End If
 if (condition)
 { 
   // condition is true 
 }
 else if (othercondition)
 { 
   // condition is false and othercondition is true
 }
 If condition Then 
   'condition is true
 ElseIf othercondition
   'condition is false and othercondition is true
 End If

[edit] For loop

C# Visual Basic .NET
 for (int i = 0; i < number; i++)
 {
   // Loop from zero up to one less than number
 }
 For i As Integer = 0 to number - 1
   ' Loop from zero up to one less than number
 Next
 for (int i = number; i >= 0; i--)
 {
   // Loops from number down to zero
 }
 For i As Integer = number to 0 Step -1
   ' Loops from number down to zero
 Next

[edit] Adoption and Community Support

Both C# and VB.Net have high adoption rates, and very active developer communities. However, C# does have an advantage in terms of the level of community support. While Microsoft fully supports both products, internally C# has higher adoption, and Microsoft provides more examples and performs more live demos using C#. Some of this disparity may be explained by the splintering of the VB developer community - Some VB developers have chosen to not upgrade to VB.Net. It is difficult to compare statistics from search engines since although items of interest on C# can be found by using the search term C# or C Sharp, equivalent searches for VB .Net are complicated by the fact that some articles choose to use the full name "Visual Basic .Net". However for the record:

Examples of the increased community and industry include:

  • A Google search for C# returns 115,000,000 hits. VB.Net returns 109,000,000 (August 6th 2006).
  • blogs.msdn.com, the blogging site for Microsoft employees, has 31,600 posts that discuss C#, while only 7,720 mention VB.Net (August 6th 2006)
  • Technorati, a technology-centric blog index finds 20,930,758 with the term C#, while only 23,377 contain VB.Net (August 6th 2006)
  • A Google search for "C#" returns 80,700,000 hits. "C Sharp" returns 4,210,000. "Visual Basic .Net" returns 13,200,000 "VB .Net" search returns 32,700,000 hits. (August 6th 2006)

As counter examples

  • Google Groups, a Usenet search engine returns 2,050,000 hits for "VB .Net", and 1,410,000 for C#
  • Amazon returns 478 hits for C#, and 610 hits for "Visual Basic .Net" (August 6th 2006).

[edit] Other Languages

[edit] C++/CLI (Formerly Managed C++)

C++/CLI (a replacement for Managed C++) does not have the adoption rate of C# or VB.NET, but does have a significant following. C++/CLI syntactically, stylisticly, and culturally is closest to C#. However, C++/CLI stays closer to its C++ roots than C# does. C++/CLI directly supports pointers, deconstructors, and other unsafe program concepts which are not supported or limited in the other languages. C++/CLI is used for porting native/legacy C++ applications into the .NET framework, or cases where the programmer wants to take more control of the code; but this control comes at a significant cost of ease of use and readability. Many of the automated tools that come with Visual Studio have reduced functionality when interacting with C++ code. This is because reflection cannot provide as much information about the code as it can for C# and VB.net

[edit] J#

J# runs a distant fourth in terms of adoption. J# is a language primarily designed to ease the transition of Java applications to the .NET framework; it allows developers to leave much of their Java or J++ code unchanged while still running it in the .NET framework, thus allowing them to migrate small pieces of it into another .NET language, such as C#, individually. J# does not receive the same level of updates as the other languages, and does not have the same level of community support. For example, Visual Studio 2005 supports automatic generation of Unit Tests in C#, VB.Net, and C++, but excludes J#. Microsoft recommends against developing new applications in J#.

[edit] Minor Languages

There are many additional languages available for the .NET Platform.

[edit] CIL

As all .NET languages compile down to Common Intermediate Language (CIL), it is only logical that some people code directly in CIL. This can be done for performance or security reasons, or just for fun. It is a very common practice to make source changes in the original C# or VB.NET, and then compare the resulting CIL, to see what benefits or consequences might result. Coding directly in CIL often makes code that is difficult or impossible to de-compile to a higher level language like C#. Either the decompile fails, or the resulting code is not very readable. This is analogous to writing directly in assembly language, and then decompiling to C++. It is possible to code an entire application directly in CIL, but this would be very cumbersome.

[edit] External links

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu