1 / 21

Platforms and tools for Web Services and Mobile Applications Introduction to C#

This introduction to C# covers the basics of the language, including its object-oriented nature, compatibility with the .NET framework, and its similarities and differences with Java and C++. It also explores the development environment options and the advantages and disadvantages of using C#.

alexandrac
Download Presentation

Platforms and tools for Web Services and Mobile Applications Introduction to C#

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. Platforms and tools for Web Services and Mobile ApplicationsIntroduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004

  2. Introduction to C# What is C# • Java like language from Microsoft • Object Orientated Language • Derived from C++ • Has the power of C++ and the simplicity of Visual Basic • Part of Microsoft .NET framework • If you are serious about .Net you need to learn C#

  3. Introduction to C# What is C# (con’t) (or not) • Cross Platform • Can only run on Windows OS • Cross Language • Able to use objects created in C++.NET and Visual Basic.NET and all the other .NET Languages

  4. Introduction to C# • What do you need? • Windows OS Machine. • Windows 2000, XP or 2003 • Microsoft .NET SDK • www.microsoft.com • Text Editor • Save files with a .cs extension Getting started with C#

  5. Introduction to C# • What about a development environment? • Visual C++ from Visual Studio 6.0 • Requires registry tweaking • Visual Studio.NET • 3rd Party software • Emacs and XEmacs • Borland Getting started with C# (con’t)

  6. .cs .exe .dll Source Code Microsoft Intermediate Language (MSIL) CLS Compliant Languages C# vs. The World How does C# work? • Compilation Process csc CPU code JIT

  7. C# vs. The World How does C# work? (con’t) • Common Language Runtime (CLR) • Provides an execution engine for developers code • Code management (loading and execution) • Memory management • Garbage Collection • Verification of type safety • Enforcement of code access security • Interoperation between managed code, COM objects, and pre-existing DLLs

  8. C# vs. The World The Language (con’t) • Hello world using System; class HelloWorld { public static void Main() { Console.WriteLine(“Hello World!"); } } >csc HelloWorld.cs >Hello World!

  9. public class button { private string caption; public string Caption { get { return caption; } set { if (value != null) caption = value; } } } button b = new button(); b.Caption = “abc” string s = b.Caption; C# vs. The World The Language (con’t) • Properties

  10. By Reference public static void Swap(ref int x, ref int y) { int z = x; x = y; y = z; } C# vs. The World • Parameter Passing The Language (con’t) • By Value

  11. C# vs. The World The Language (con’t) • Pointers • Not recommended for use public struct Node { public int value; public unsafe Node* next; } public unsafe class A { . . . public class A { public unsafe void B (char *p) { . . .

  12. C# vs. The World The Language (con’t) • Boxing / Unboxing • Allows value types to be converted to and from objects automatically ArrayList list = new ArrayList(); int z = 100; list.Add(1); list.Add(13.12); list.Add(z); //integers are automatically boxed //when they are added to the list

  13. C# vs. The World The Language (con’t) • Delegates • Basically a type-safe object orientated function pointer delegate void simpleDelegate(); Class Test { static void F() { System.Console.Writeline(“Test.F”); } static void main (){ simpleDelegate d = new simpleDelegate(F); d(); } }

  14. C# vs. The World The Language (con’t) • Delegates (con’t) void multiCall (simpleDelegate d, int count) { for (int i=0; i<count; i++){ d(); }

  15. v.1 v.2 Class A Class A x(); x(); y(); Which one to use? Class B Class B y(); y(); C# vs. The World The Language (con’t) • Versioning

  16. C# vs. The World The Language (con’t) • Versioning • C# requires developers to clearly state their intent • Use of the keyword ‘new’ and ‘override’ Class Derived B { new public void x () { . . . Class Derived B { public override void x () { . . .

  17. C# vs. The World • Libraries The Language (con’t) • Few core libraries • Uses the libraries from the .NET framework • Threading, Collection, XML, ADO+, ASP+, GDI+ & WinForms libraries

  18. C# vs. The World Comparison of C# syntax with Java and C++ • Similarities • Single rooted class hierarchy • Similar keywords (derived from C++) • Virtual Machine & IL/CLR • Garbage Collection • No global methods • Interface, no Multiple inheritance • Exception handling

  19. C# vs. The World Comparison of C# syntax with Java and C++ • Differences • Syntax and Keywords not from C++ • Properties, Delegates, Boxing, Pointers, Libraries, etc. • Preprocessor Directives

  20. C# vs. The World C# Advantages • Easy to learn, similar to both C++ and JAVA • Can use existing pool of C++ and Visual Basic programmers. • Can use components from .NET • Syntactical Sugar

  21. C# vs. The World C# Disadvantages • Only runs on Windows machines • Limited choice in development environment • Locked into Microsoft compatibility • Not extensively tested • Not enough maturity time

More Related