Upload
alexander-hogan
View
218
Download
1
Tags:
Embed Size (px)
Citation preview
Comparison ofComparison ofC# and VB.NetC# and VB.Net
By
Sam NasrOctober 26, 2004October 26, 2004
What is C#?What is C#? C# (C-Sharp) is a new language developed by C# (C-Sharp) is a new language developed by
Microsoft Corporation.Microsoft Corporation.
Designed by Anders Hejlsberg (creator of Turbo Designed by Anders Hejlsberg (creator of Turbo Pascal and architect of Delphi), Scott Wiltamuth, Pascal and architect of Delphi), Scott Wiltamuth, and Peter Golde. and Peter Golde.
Described as a “...simple, modern, object-oriented, Described as a “...simple, modern, object-oriented, and type-safe programming language derived from and type-safe programming language derived from C and C++”. C and C++”.
Bears many syntactic similarities to C++ and Java. Bears many syntactic similarities to C++ and Java.
What is VB.Net?What is VB.Net?
VB.Net is the latest release of Microsoft’s VB.Net is the latest release of Microsoft’s Visual Basic language.Visual Basic language.
VB is an event driven programming language.VB is an event driven programming language.
Derived heavily from BASIC.Derived heavily from BASIC.
VB enables Rapid Application Development VB enables Rapid Application Development (RAD) of graphical user interface (GUI) (RAD) of graphical user interface (GUI) applications.applications.
MythsMyths
VB.Net is intended for use with VB.Net is intended for use with Microsoft Office.Microsoft Office.
C# is the latest release of C++.C# is the latest release of C++. C# is easier to learn than VB.Net.C# is easier to learn than VB.Net. To better understand C#, one should To better understand C#, one should
first learn C++.first learn C++. A .Net solution can contain only 1 A .Net solution can contain only 1
language.language.
Language DifferencesLanguage Differences
The differences of the 2 languages lie The differences of the 2 languages lie in:in:
1.1. SyntaxSyntax
2.2. Object Oriented FeaturesObject Oriented Features
3.3. Visual Studio.Net IDEVisual Studio.Net IDE
Syntax DifferencesSyntax Differences Case SensitivityCase Sensitivity Line TerminationLine Termination CommentsComments Namespace Declaration and Namespace Declaration and
UsageUsage Variable DeclarationVariable Declaration Variable InitializationVariable Initialization Declaring Function Declaring Function
ParametersParameters Passing Function ParametersPassing Function Parameters Optional Parameters Optional Parameters Parameter ListsParameter Lists Method DeclarationMethod Declaration Returning Output ParametersReturning Output Parameters Program StartupProgram Startup Exiting Exiting
Programs/Methods/LoopsPrograms/Methods/Loops
Member ScopeMember Scope Static/Shared MethodsStatic/Shared Methods Classes versus ModulesClasses versus Modules If statementsIf statements Short CircuitingShort Circuiting Conditional StatementsConditional Statements Properties and IndexersProperties and Indexers ArraysArrays For LoopsFor Loops For/Each LoopsFor/Each Loops Try/Catch BlocksTry/Catch Blocks Attribute UsageAttribute Usage Control CharactersControl Characters Type Comparison and Type Comparison and
ConversionConversion
C# ExampleC# Example(Syntax)(Syntax)
/* C Style comment *//* C Style comment */
// C++ Style comment// C++ Style comment
///Enhanced comment for Documentation Feature///Enhanced comment for Documentation Feature
Void SampleProc()Void SampleProc()
{{
int intCounter1=0;int intCounter1=0;
MessageBox.show(“Counter1=” + MessageBox.show(“Counter1=” + intCounter1.ToString());intCounter1.ToString());
} //end of SampleProc} //end of SampleProc
VB.Net ExampleVB.Net Example(Syntax)(Syntax)
‘‘Style of comments for VB.NetStyle of comments for VB.Net
Sub SampleProc()Sub SampleProc()
Dim intCounter1 as Integer, intCounter2 as Dim intCounter1 as Integer, intCounter2 as IntegerInteger
MessageBox.show(“Counter1=” & intCounter1)MessageBox.show(“Counter1=” & intCounter1)
End Sub ‘end of SampleProcEnd Sub ‘end of SampleProc
Object-Oriented FeaturesObject-Oriented Features
Inheritance SyntaxInheritance Syntax Method OverloadingMethod Overloading ConstructorsConstructors Invoking Other Invoking Other
Constructors Constructors Invoking Base Invoking Base
Constructors Constructors InitializersInitializers Hiding Base Class Hiding Base Class
MembersMembers
Overriding methodsOverriding methods Requiring/Preventing Requiring/Preventing
InheritanceInheritance Declaring and Declaring and
Implementing Implementing InterfacesInterfaces
Delegated and EventsDelegated and Events Comparing ClassesComparing Classes String ComparisonsString Comparisons
C# ExampleC# Example(Object Oriented)(Object Oriented)
class Appclass App{{ static void Main(string [ ] args)static void Main(string [ ] args) { { int intCounter=0;int intCounter=0;
foreach (string arg in args)foreach (string arg in args) {{ System.Console.WriteLine(“Counter:” + intCounter.ToString() System.Console.WriteLine(“Counter:” + intCounter.ToString()
+ “=“ + arg);+ “=“ + arg); } //end of foreach} //end of foreach
} //end of Main()} //end of Main()
} //end of App{}} //end of App{}
VB.Net ExampleVB.Net Example(Object Oriented)(Object Oriented)
Class AppClass App Shared Sub Main(ByVal args as String( ) )Shared Sub Main(ByVal args as String( ) ) Dim arg as StringDim arg as String Dim intCounter as IntegerDim intCounter as Integer
For Each arg in argsFor Each arg in args System.Console.Writeline(“Counter: ” & System.Console.Writeline(“Counter: ” &
intCounter & “=“ & arg)intCounter & “=“ & arg) Next ‘For Each loopNext ‘For Each loop
End Sub ‘end of Main()End Sub ‘end of Main()
End Class ‘end of App{}End Class ‘end of App{}
IDE DifferencesIDE Differences
AssemblyInfo.xAssemblyInfo.x Default/Root Default/Root
NamespaceNamespace Startup objectStartup object App.icoApp.ico Imports/UsingImports/Using
COM ReferencesCOM References Compiler ConstantsCompiler Constants Options:Options:
(Explicit, Strict, (Explicit, Strict, Compare)Compare)
Errors and Errors and WarningsWarnings
Specific Language Specific Language FeaturesFeatures
Unsafe Blocks (C#)Unsafe Blocks (C#) Using (C#)Using (C#) Documentation Comments (C#)Documentation Comments (C#) Operator Overloading (C#)Operator Overloading (C#) Late Binding (VB)Late Binding (VB)
Unsafe Blocks (C#)Unsafe Blocks (C#)class Class1class Class1
{{
static unsafe void main (string[ ] args)static unsafe void main (string[ ] args)
{ {
string sName = “Joe Mojica”;string sName = “Joe Mojica”;
fixed (char *Temp = sName)fixed (char *Temp = sName)
{{
char *ch= Temp;char *ch= Temp;
ch +=4;ch +=4;
*ch = (char)o;*ch = (char)o;
ch += 1;ch += 1;
*ch = (char) o;*ch = (char) o;
}}
System.Console.WriteLine(sName);System.Console.WriteLine(sName);
}}
}}
Using (C#)Using (C#)
void OpenDatabase()void OpenDatabase()
{{
string cstr;string cstr;
cstr = "Provider=Microsoft.Jet.OLEDB.4.0";cstr = "Provider=Microsoft.Jet.OLEDB.4.0";
cstr += "Data Source=c:\\MyDB.mdb;";cstr += "Data Source=c:\\MyDB.mdb;";
using (OleDBConnection conn = new OleDBConnection(Cstr))using (OleDBConnection conn = new OleDBConnection(Cstr))
{{
conn.open();conn.open();
}}
}}
Documentation Documentation Comments (C#)Comments (C#)
///<summary>///<summary>
///A Sample Function to demonstrate C#///A Sample Function to demonstrate C#
///</summary>///</summary>
///<param name=“void”>This function does not receive a ///<param name=“void”>This function does not receive a parameter. </param>parameter. </param>
///<returns>Void Type</returns>///<returns>Void Type</returns>
Void SampleProc()Void SampleProc()
{{
int intCounter1, intCounter2;int intCounter1, intCounter2;
MessageBox.show(“Counter1=” & intCounter1);MessageBox.show(“Counter1=” & intCounter1);
} //end of SampleProc} //end of SampleProc
Controversial IssuesControversial Issues
PointPoint C# offers less typing.C# offers less typing. C# is a better programming language C# is a better programming language
because it forces variables to be defined.because it forces variables to be defined. C# code runs faster.C# code runs faster.
Counter-PointCounter-Point VB.Net offers automatic case settingVB.Net offers automatic case setting VB.Net offers Option ExplicitVB.Net offers Option Explicit Speed is debatable!Speed is debatable!
Which Language do I Which Language do I choose for my organization?choose for my organization? Which language features do I need?Which language features do I need? Which language features can I live without?Which language features can I live without? What is the background of the staff?What is the background of the staff? Which language does my staff work more Which language does my staff work more
comfortably with?comfortably with? Can staff members be comfortable with Can staff members be comfortable with
both?both? What is the availability of Human What is the availability of Human
Resources for a specific language?Resources for a specific language?
Language ConvertersLanguage Converters
C# to VB.NETC# to VB.NET http://www.aspalliance.com/aldotnet/examples/http://www.aspalliance.com/aldotnet/examples/
translate.aspxtranslate.aspx http://www.kamalpatel.net/ConvertCSharp2VB.aspx http://www.kamalpatel.net/ConvertCSharp2VB.aspx
VB.Net to C#VB.Net to C# http://www.e-iceblue.comhttp://www.e-iceblue.com http://www.vbconversions.comhttp://www.vbconversions.com
Additional InformationAdditional Information
C# & VB.NET Conversion Pocket C# & VB.NET Conversion Pocket ReferenceReference by Jose Mojica by Jose Mojica
C# in a Nutshell C# in a Nutshell By By Peter DraytonPeter Drayton, , Ben AlbahariBen Albahari, Ted Neward, Ted Neward
http://en.wikipedia.org/wiki/http://en.wikipedia.org/wiki/Visual_Basic_programming_languageVisual_Basic_programming_language
Upcoming EventsUpcoming Events MSDN Event MSDN Event
(http://msevents.microsoft.com)(http://msevents.microsoft.com)Thursday (10/28/2004), 1:00 – 5:00 PM at Regal Thursday (10/28/2004), 1:00 – 5:00 PM at Regal Town Cinemas. FreeTown Cinemas. Free
New SQL Server SIGNew SQL Server SIGEvery 3Every 3rdrd Thursday 6:30-8:30 PM Thursday 6:30-8:30 PMALG - 30640 Bainbridge Road in SolonALG - 30640 Bainbridge Road in Solon
Next meeting: COM and .Net ComponentsNext meeting: COM and .Net Components Thursday, Nov 23, 2004 6:30-8:30 PMThursday, Nov 23, 2004 6:30-8:30 PM
Career InfoCareer Info Intuit Corp is seeking 2 Sr. .Net Developers. Contact Heather Intuit Corp is seeking 2 Sr. .Net Developers. Contact Heather
Winchester ([email protected]) at 214-387-2125. See Winchester ([email protected]) at 214-387-2125. See www.intuit.com/about_intuit/careers for more info.www.intuit.com/about_intuit/careers for more info.
Adaptive Solutions Group is seeking several C# web developers for Adaptive Solutions Group is seeking several C# web developers for contract to hire. Contact Matt Twyman ([email protected]) contract to hire. Contact Matt Twyman ([email protected]) at 314-236-3853. See www.adaptivesg.com for more info.at 314-236-3853. See www.adaptivesg.com for more info.
Robert Half Technology is accepting resumes for various Robert Half Technology is accepting resumes for various development positions. Contact Kim Nasierowski development positions. Contact Kim Nasierowski ([email protected]) at 216-621-6633. See www.rht.com ([email protected]) at 216-621-6633. See www.rht.com for more info.for more info.
Tek Systems is accepting resumes for various development positions. Tek Systems is accepting resumes for various development positions. Contact Janelle Capretta ([email protected]) at 216-654- Contact Janelle Capretta ([email protected]) at 216-654-1840. See http://www.teksystems.com for more info.1840. See http://www.teksystems.com for more info.
Invesmart is seeking 2 VB.Net developer positions. See Invesmart is seeking 2 VB.Net developer positions. See www.invesmart.comwww.invesmart.com