230 likes | 374 Views
.NET Tech Talk Series. Intro to C#. Wednesday, February 5 th , 2003. Michael Dunn ( mdunn@cs.drexel.edu ) Drexel University Student Ambassador to Microsoft Mid-Atlantic Student Ambassador Team Lead MCS Society Vice President. Agenda. Introduction What is C#? A first look at C# Code demo
E N D
.NET Tech Talk Series Intro to C# Wednesday, February 5th, 2003 • Michael Dunn ( mdunn@cs.drexel.edu ) • Drexel University Student Ambassador to Microsoft • Mid-Atlantic Student AmbassadorTeam Lead • MCS Society Vice President
Agenda • Introduction • What is C#? • A first look at C# • Code demo • C# features • Conclusion • Questions • Raffle
Introduction • Third in a series of .NET Technical Talks sponsored by Microsoft and Drexel’s Math and Computer Science Society. • Summary of last talk: • Keep your old C++ code, and inter-operate with .NET using C++.NET to get access to the class library, security, and garbage collection. • As usual: • Please remember to fill out evaluations – you can’t win a door prize without a completed form • Please hold detailed questions till the end
What is C#? • A new object oriented language • Syntax based on C • Similar to C++ and Java • Used to write .NET software • Software that targets the .NET Framework is called managed code • C# gains much from the .NET Framework • Internet oriented platform • JIT compilation • Automatic memory management • Security, type-safety • Framework Class Library
What is C#? • Existing languages are powerful. Why do we need another language? • Important features are spread out over multiple languages • choose between pointers (C++) • or garbage collection (Java) • Old languages + new features = poor syntax • Garbage collection in C++? • Event-driven GUIs in Java?
What is C#? • Derived from the features and syntaxes of other languages • The safety of Java • The ease of Visual Basic • The power of C++
What is C#? • The safety of Java • 100% object oriented • Automatic garbage collection • Array bounds checking at runtime • Strict type checking • Structured exception handling
What is C#? • The ease of Visual Basic • First class support for properties • First class support for events • For-each loops
What is C#? • The power of C++ • Enumerations • Operator overloading • Mathematical, Indexing, and Casting • Function pointers • Called “delegates” • Type safe • Structs • Option to pass parameters by reference of by value • Can disable type-safety, garbage collection, and bounds checking • Can directly manipulate memory with pointers
A first look at C# using System.Windows.Forms; using System.Drawing; class MyForm:Form { public static void Main() { Application.Run(new MyForm()); } protected override void OnPaint(PaintEventArgs e){ e.Graphics.DrawString("Hello World!", new Font("Arial", 35), Brushes.Blue, 10, 100); } }
What is C#? • Most users think of two types of objects • “Real” objects – Customer, Order, etc. • Primitive types – int, float, bool • Different expectations for each • Real objects are more expensive to create • Primitives always have a value • Primitives have operator support
What is C#? • Traditional views • C++, Java: Primitive types are “magic” and do not interoperate with objects • C# offers improved extensibility and reusability • New primitive types: Decimal, SQL, … • Collections, etc., work for all types
object Stream Hashtable int double MemoryStream FileStream What is C#? • Unified type system • All types ultimately inherit from object • Classes, enums, arrays, delegates, structs, … • An implicit conversion exists from any type to type object
What is C#? • 76 keywords: abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto If implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void while
Assembly Language Compiler C++.NET primer (cont.) Compilation Code(IL) Source Code Metadata Native Code JIT Compiler Execution
C++.NET primer • C++.NET is _not_ a dramatically different language from your daddy’s C++ • “Everett” C++.NET will be 98% compliant with the ISO standard • “Everett” will ship with /GS compiler flag to catch buffer overflows • The syntax generally remains the same, while the compiler emits entirely different instructions • Due to Intermediate Language (IL), machine instructions are generated at runtime
C++.NET primer • Why use C++.NET over C#, or other .NET languages • Use managed or unmanaged code • Keep using your low-level or performance critical native code alongside .NET • Lots of code already written in C++ /clr compiler switch – “IJW” (It Just Works) • Use cross-language debugging and all the other neat .NET tricks
C++.NET demo Live demo of C++.NET with Visual Studio.NET 2002
Conclusions • C++.NET targets the same lower-level developers as Visual C++ 6. • Compile your old C++ code using the C++.NET compiler to get the advantages of .NET. • Moving toward ISO standardization
Next tech talk • Next week, Wednesday! • Same time, same place • Topic: Intro to C# • More books, software and food
Further references • http://www.gotdotnet.com/team/cplusplus/ • http://msdn.microsoft.com/visualc/ • http://www.cplusplus.com/
Questions / Raffle • Send your evaluations forward!