22
Comparison of Comparison of C# and VB.Net C# and VB.Net By Sam Nasr October 26, 2004 October 26, 2004

Csv b Net Comparison

Embed Size (px)

DESCRIPTION

CS Vs VB comparison

Citation preview

  • Comparison ofC# and VB.Net

    BySam NasrOctober 26, 2004

  • What is C#?C# (C-Sharp) is a new language developed by Microsoft Corporation.

    Designed by Anders Hejlsberg (creator of Turbo Pascal and architect of Delphi), Scott Wiltamuth, and Peter Golde.

    Described as a ...simple, modern, object-oriented, and type-safe programming language derived from C and C++.

    Bears many syntactic similarities to C++ and Java.

  • What is VB.Net?VB.Net is the latest release of Microsofts Visual Basic language.

    VB is an event driven programming language.

    Derived heavily from BASIC.

    VB enables Rapid Application Development (RAD) of graphical user interface (GUI) applications.

  • MythsVB.Net is intended for use with Microsoft Office.C# is the latest release of C++.C# is easier to learn than VB.Net.To better understand C#, one should first learn C++.A .Net solution can contain only 1 language.

  • Language Differences

    The differences of the 2 languages lie in:SyntaxObject Oriented FeaturesVisual Studio.Net IDE

  • Syntax DifferencesCase SensitivityLine TerminationCommentsNamespace Declaration and UsageVariable DeclarationVariable InitializationDeclaring Function ParametersPassing Function ParametersOptional Parameters Parameter ListsMethod DeclarationReturning Output ParametersProgram StartupExiting Programs/Methods/Loops

    Member ScopeStatic/Shared MethodsClasses versus ModulesIf statementsShort CircuitingConditional StatementsProperties and IndexersArraysFor LoopsFor/Each LoopsTry/Catch BlocksAttribute UsageControl CharactersType Comparison and Conversion

  • C# Example(Syntax)/* C Style comment */// C++ Style comment

    ///Enhanced comment for Documentation FeatureVoid SampleProc() { int intCounter1=0; MessageBox.show(Counter1= + intCounter1.ToString()); } //end of SampleProc

  • VB.Net Example(Syntax)

    Style of comments for VB.Net

    Sub SampleProc() Dim intCounter1 as Integer, intCounter2 as Integer MessageBox.show(Counter1= & intCounter1)End Sub end of SampleProc

  • Object-Oriented FeaturesInheritance SyntaxMethod OverloadingConstructorsInvoking Other Constructors Invoking Base Constructors InitializersHiding Base Class MembersOverriding methodsRequiring/Preventing InheritanceDeclaring and Implementing InterfacesDelegated and EventsComparing ClassesString Comparisons

  • C# Example(Object Oriented)class App{ static void Main(string [ ] args) { int intCounter=0;

    foreach (string arg in args) { System.Console.WriteLine(Counter: + intCounter.ToString() + = + arg); } //end of foreach

    } //end of Main()

    } //end of App{}

  • VB.Net Example(Object Oriented)Class App Shared Sub Main(ByVal args as String( ) ) Dim arg as String Dim intCounter as Integer

    For Each arg in args System.Console.Writeline(Counter: & intCounter & = & arg) Next For Each loop

    End Sub end of Main()

    End Class end of App{}

  • IDE DifferencesAssemblyInfo.xDefault/Root NamespaceStartup objectApp.icoImports/Using

    COM ReferencesCompiler ConstantsOptions: (Explicit, Strict, Compare)Errors and Warnings

  • Specific Language FeaturesUnsafe Blocks (C#)Using (C#)Documentation Comments (C#)Operator Overloading (C#)Late Binding (VB)

  • Unsafe Blocks (C#)class Class1{ static unsafe void main (string[ ] args) { string sName = Joe Mojica; fixed (char *Temp = sName) { char *ch= Temp; ch +=4; *ch = (char)o; ch += 1; *ch = (char) o; }

    System.Console.WriteLine(sName); }}

  • Using (C#)void OpenDatabase(){ string cstr; cstr = "Provider=Microsoft.Jet.OLEDB.4.0"; cstr += "Data Source=c:\\MyDB.mdb;";

    using (OleDBConnection conn = new OleDBConnection(Cstr)) { conn.open(); }}

  • Documentation Comments (C#)//////A Sample Function to demonstrate C#//////This function does not receive a parameter. ///Void Type

    Void SampleProc() { int intCounter1, intCounter2; MessageBox.show(Counter1= & intCounter1);} //end of SampleProc

  • Controversial IssuesPointC# offers less typing.C# is a better programming language because it forces variables to be defined.C# code runs faster.

    Counter-PointVB.Net offers automatic case settingVB.Net offers Option ExplicitSpeed is debatable!

  • Which Language do I choose for my organization?Which language features do I need?Which language features can I live without?What is the background of the staff?Which language does my staff work more comfortably with?Can staff members be comfortable with both?What is the availability of Human Resources for a specific language?

  • Language ConvertersC# to VB.NEThttp://www.aspalliance.com/aldotnet/examples/translate.aspxhttp://www.kamalpatel.net/ConvertCSharp2VB.aspx

    VB.Net to C#http://www.e-iceblue.comhttp://www.vbconversions.com

  • Additional InformationC# & VB.NET Conversion Pocket Reference by Jose Mojica

    C# in a Nutshell ByPeterDrayton, BenAlbahari, TedNeward http://en.wikipedia.org/wiki/Visual_Basic_programming_language

  • Upcoming EventsMSDN Event (http://msevents.microsoft.com)Thursday (10/28/2004), 1:00 5:00 PM at Regal Town Cinemas. Free

    New SQL Server SIGEvery 3rd Thursday 6:30-8:30 PMALG - 30640 Bainbridge Road in Solon

    Next meeting: COM and .Net Components Thursday, Nov 23, 2004 6:30-8:30 PM

  • Career InfoIntuit Corp is seeking 2 Sr. .Net Developers. Contact Heather Winchester ([email protected]) at 214-387-2125. See www.intuit.com/about_intuit/careers for more info.

    Adaptive Solutions Group is seeking several C# web developers for contract to hire. Contact Matt Twyman ([email protected]) at 314-236-3853. See www.adaptivesg.com for more info.

    Robert Half Technology is accepting resumes for various development positions. Contact Kim Nasierowski ([email protected]) at 216-621-6633. See www.rht.com for more info.

    Tek Systems is accepting resumes for various development positions. Contact Janelle Capretta ([email protected]) at 216-654-1840. See http://www.teksystems.com for more info.

    Invesmart is seeking 2 VB.Net developer positions. See www.invesmart.com