|
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. Programming languages are used for controlling the behavior of a machine (often a computer). ...
Programming languages are used for controlling the behavior of a machine (often a computer). ...
// Programming language statements typically have conventions for: statement separators; statement terminators; and line continuation A statement separator is used to demarcate boundaries between two separate statements. ...
// Different languages use different symbols for the concatenation operator. ...
String functions are used in computer programming languages to manipulate a string or query information about a string (some do both). ...
In computer science, an evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. ...
The nearest living sibling to ALGOL 68 may be C++, making this a good comparison candidate: C++ doesnt have: PROC - nested functions, OP and PRIO - definable operator symbols and priorities, garbage collection, use before define, formatted transput using complex formatting declarations, := - assignment operation symbol (to avoid confusion with equal...
The C and C++ programming languages are closely related, as C++ grew out of C and is many ways a superset of the latter. ...
This article or section is in need of attention from an expert on the subject. ...
This is a comparison of the Java programming language with the C++ programming language. ...
This is a comparison of the C# programming language with the Java programming language. ...
The Microsoft . ...
Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ...
Languages are high level programming languages like Visual Basic, C#, etc. ...
The title given to this article is incorrect due to technical limitations. ...
Visual Basic . ...
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. A diagram of the operation of a typical multi-language, multi-target compiler. ...
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. ...
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected. ...
No second class languages | | The neutrality of this article is disputed. Please see the discussion on the talk page. | 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. Image File history File links Broom_icon. ...
Image File history File links Unbalanced_scales. ...
Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ...
It has been suggested that Maintenance OS be merged into this article or section. ...
Usability is a term used to denote the ease with which people can employ a particular tool or other human-made object in order to achieve a particular goal. ...
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. Visual Basic (VB) is an event driven programming language and associated development environment from Microsoft for its COM programming model. ...
In computer science, the term object-based has two different, incompatible senses: A somehow limited version of object-oriented programming where one or more of the following restrictions applies: there is no implicit inheritance there is no polymorphism only a very reduced subset of the available values are objects (typically...
Object-oriented analysis and design (OOAD) is often part of the development of large scale systems and programs often using the Unified Modeling Language (UML). ...
Component Object Model (COM) is a Microsoft platform for software componentry introduced by Microsoft in 1993. ...
Object-oriented analysis and design (OOAD) is often part of the development of large scale systems and programs often using the Unified Modeling Language (UML). ...
The title given to this article is incorrect due to technical limitations. ...
Java is a programming language originally developed by Sun Microsystems and released in 1995. ...
Delphi is the primary programming language of Borland Delphi. ...
C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
Java is a programming language originally developed by Sun Microsystems and released in 1995. ...
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.
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 Rapid application development (RAD), is a software development process developed initially by James Martin in the 1980s. ...
- Optional declaration of variables
- Optional Weak Typing using late binding
- Optional Parameters
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. Delphi is the primary programming language of Borland Delphi. ...
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 centered around the IDE. Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its functionality but make it sweeter for humans to use. ...
This article or section does not cite any references or sources. ...
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. 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
- Static classes (Classes which cannot contain any non-static members, although VB's Modules are essentially sealed static classes with additional semantics)
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 - 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 mathematical operations on each condition.
- The
MyClass keyword which performs a non-virtual method call on an overridden method - In VB functions, a variable of the same name and type is implicitly created. For example, in a boolean function named DoSomething(), this code is valid:
DoSomething = True;[2] the variable DoSomething may even be passed by reference to another routine and modified by it: dosomethingElse(DoSomething). In C#, the latter would require 3 statements bool retval = true; dosomethingElse(ref retval); return retval;. 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. For example, Visual Basic .NET has support for the legacy MsgBox() in addition to the fully-qualified .NET call of System.Windows.Forms.MessageBox.Show() - Optional variable declaration
- Optional strong typing
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.
- Lack of optional parameters in functions, a feature present in both Visual Basic.NET and C++ (This is done on purpose to force the programmer to use Polymorphism and/or Generics).
Syntax comparisons One of the large differences is in blocks. VB terminates a block of code with End BlockName, for example: While something End While
In C# the use of braces, {}, to delimit blocks will be more familiar to programmers with experience in other modern languages.
Keywords Keywords are very different between the two languages. C# uses keywords that might be familiar to programmers, whereas VB uses keywords that more accurately describe their role. A comparison: (VB vs C#) Me vs this - a self-reference to the current object instance MyBase vs base - for referring to the base class from which the current class is derived Shared vs static - for declaring methods that do not require an explicit instance of an object NotInheritable vs sealed - for declaring classes that may not be inherited NotOverridable vs sealed - for declaring methods that may not be overridden by derived classes MustInherit vs abstract - prevents a class from being directly instantiated, and forces consumers to create objects references to only derived classes MustOverride vs abstract - for forcing derived classes to override this method Overridable vs virtual - declares a method as being able to be overriden in derived classes Notice above how some C# keywords such as sealed are used to represent different things when applied to method or class definitions. VB, on the other hand, uses different keywords for different contexts.
Comments | C# | Visual Basic .NET | | // Single Line Comment | ' Single Line Comment | | /* Multi-line comment */ The title given to this article is incorrect due to technical limitations. ...
Visual Basic . ...
| N/A | | /// XML Comments | ''' XML Comments | The characters N/A (sometimes n/a) are an abbreviation that is mainly used in information tables. ...
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 Then 'condition is false and othercondition is true End If | The title given to this article is incorrect due to technical limitations. ...
Visual Basic . ...
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 | The title given to this article is incorrect due to technical limitations. ...
Visual Basic . ...
Equality and other comparison operators | C# | Visual Basic .NET | if (a == b) { // equal } | If a = b Then ' equal End If | if (a != b) { // not equal } | If a <> b Then ' not equal End If | | if ((a == b) && (c == d)) { // multiple comparisons: } | If a = b And c = d Then ' multiple comparisons End If --- Note: There is a small difference between these two blocks: In the C# example, condition (c == d) doesn't get evaluated if the first condition (a == b) is false. Instead, in the VB.NET example, the second condition will get evaluated no matter what the first condition (a = b) result is. To perfectly emulate the C# code, the VB.NET code should be written this way: --- If a = b AndAlso c = d Then ' multiple comparisons End If | The title given to this article is incorrect due to technical limitations. ...
Visual Basic . ...
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 Inc. ...
Google Inc. ...
- 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).
Usenet (USEr NETwork) is a global, decentralized, distributed Internet discussion system that evolved from a general purpose UUCP architecture of the same name. ...
Amazon. ...
Other languages 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 It has been suggested that this article or section be merged with Managed Extensions for C++. (Discuss) Managed C++ is one of Microsofts new managed languages for their . ...
In computer science, a programming language is formally type safe when the language explicitly defines the outcome when a programmer stores a value as one type but retrieves it as a different type (a technique known as casting when done intentionally). ...
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#. The J# (pronounced J-sharp) programming language is a transitional language for programmers of Suns Java and Microsofts J++ languages, so they may use their existing knowledge, and applications on Microsofts . ...
Minor languages There are many additional languages available for the .NET Platform.
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 [verification needed]. 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. Common Intermediate Language (CIL) (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable programming language in the Common Language Infrastructure and in the . ...
See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ...
External links |