1 / 23

.NET Tech Talk Series

.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

haley
Download Presentation

.NET Tech Talk Series

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .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

  2. Agenda • Introduction • What is C#? • A first look at C# • Code demo • C# features • Conclusion • Questions • Raffle

  3. 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

  4. 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

  5. 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?

  6. 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++

  7. What is C#? • The safety of Java • 100% object oriented • Automatic garbage collection • Array bounds checking at runtime • Strict type checking • Structured exception handling

  8. What is C#? • The ease of Visual Basic • First class support for properties • First class support for events • For-each loops

  9. 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

  10. 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); } }

  11. Code demo

  12. 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

  13. 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

  14. 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

  15. 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

  16. Assembly Language Compiler C++.NET primer (cont.) Compilation Code(IL) Source Code Metadata Native Code JIT Compiler Execution

  17. 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

  18. 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

  19. C++.NET demo Live demo of C++.NET with Visual Studio.NET 2002

  20. 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

  21. Next tech talk • Next week, Wednesday! • Same time, same place • Topic: Intro to C# • More books, software and food

  22. Further references • http://www.gotdotnet.com/team/cplusplus/ • http://msdn.microsoft.com/visualc/ • http://www.cplusplus.com/

  23. Questions / Raffle • Send your evaluations forward!

More Related