base type • Classes and interfaces – Interface describes members – Class provides implementation for members • Properties, methods, and events – Function members – Properties encapsulate piece of object’s state – Events simplify acting on object state changes
Windows • Microsoft standardized C# language through ECMA • However, few resources available to support C# on non-Windows platforms • Therefore, C# not full replacement for Java • Java best for multiplatform support
HTML that can run on any platform (ASP.NET) • May run on a runtime other than CLR (Mono Project) • May run on host that supports Silverlight (Flash Player)
Runtime (CLR) • CLR equipped with host of features – Automatic memory management – Exception handling • Design of C# closely maps to design of CLR • C# type system maps closely to CLR type system
+ vast set of libraries – Core libs – Applied libs (which depend on Core libs) • CLR executes managed code • C# code compiled into managed code • Managed code packaged into assembly (EXE/DLL) along with type info or metadata • Represented in Intermediate Language (IL) • CLR loads IL and converts to native code of machine via CLR JIT (Just-In-Time) compiler
// Class declaration { static void Main() // Method declaration { int x = 12 * 30; // Statement 1 Console.WriteLine(x); // Statement 2 } // End of method } // End of class
split across multiple files partial class PaymentForm { … } • Partial methods let auto-generated partial type provide customizable hooks for manual authoring partial class PaymentForm {
type (Class is reference type) – No support for • Inheritance • Parameterless constructors • Finalizers • Virtual members • Structs preferred when value-type semantics desirable – Ex. Numeric types • Define an Interface – Provides specification (contract)
Only within containing assembly or friend assemblies • Private – Only within containing type (default) • Protected – Only within containing type or subclasses
in Java – If – If-else – Switch • Iteration Statements (Loops) – Look exactly the same as in Java – While and do-while – For – Foreach • Supports Jump, Break and Continue and Goto