, 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials XML+ intro BizTalk BizTalk Seminars
, 2 Contact Thijs Holleboom 21F411 Thijs.Holleboom@kau.se 054-700 1148 Inger Bran 21E414 Inger.Bran@kau.se 054-700 1970 Per Hurtig 21F422 Per.Hurtig@kau.se 054-700 2335 Programming All programming is the same sequence iteration selection Manipulating computers Level of abstraction differs assembler, c, c++, java, c#, lisp, prolog, sql Expressiveness varies Some languages can do more If you know programming you can use any language (almost) Programming Programming Language Nifty Stuff Abstraction Pre-done stuff Sequence Iteration Selection Memory op s Calculations Computer
, 3 Programming Difficult Full control Easy Less control C++ Java C# C Byte Code CIL Assembler Assembler Virtual Machine CLR Machine code Hardware (computer and peripherals) Structure of.net technology Another visualisation of.net
, 4 Important concepts FCL Common class library CTS Common type system CLR The environment everything builds upon. The motor i a.net application. From code to program Common Language Runtime (CLR) Is essentially an implementation of the CLI Common Language Infrastructure Other implementations exist, e.g. the Mono runtime Responsible for almost everything Uses only OS for threads and bulk memory management
, 5 CLR JIT just in time-compiler Compiles code late Garbage Collector automatic memory handling You don't have to deallocate memory, it is handled by the garbage collector In C/C++ you have to take care of your own garbage, in C# you don't CLR Common Type System (CTS) All languages in the.net family are basically the same, except for the syntax You can include code written in one language into a program written in another Exception handler When something goes wrong, the exception handler comes into play. Common Intermediate Language (CIL) All.NET languages compile to CIL, which basically is advanced assembler. The JIT compiles parts of the CIL to native object code, when that part of the CIL is needed. Before JIT Stub code CIL After JIT Object code
, 6 CIL Is a strongly typed, verbose, assembler language stack-based generic low-level easy to compile has more features than are used by any existing supported language tail recursion (used in functional languages like LISP) CIL Example.assembly HelloWorld{}.method public hidebysig static void Main() cil managed {.entrypoint ldstr "Hello World!" call void [mscorlib]system.console::writeline(string) ret } Garbage Collection Allocation is fast, simple list of used memory instead of linked list Works well with cache memory Your code is smaller, simpler, and more reliable But in a sense uglier
, 7 Garbage collection You never have memory leaks But your program is almost always too big Old stuff lying around Watch out when switching to a language without GC or your program will leak alloc/free in C new/delete in C++ Garbage Collection You may be thinking that it doesn't matter how garbage collection can help you if it means your program might lock up for several seconds anytime it gets asked to do something. And you'd be right -that didsuck, back in the '70's and '80's on Lisp machines and such. Thus, garbage collection is nowadays a very fast process Common Type System (CTS) All.Net languages understand each other's data types All use the same primitives Classes from different languages can inherit from each other Value types scalars, such as integers records (eg. structs) and objects(!)
, 8 CTS Same base classes (highest level) All.Net languages highest objects can be cast to any other. Interfaces are supported like in Java Can do instead of Is-a represented by inheritance CTS All objects inherit via single inheritance from a top-most object Multiple inheritance is not supported Good(?) multiple inheritance is complex multiple inheritance is seldom needed interfaces are better Object Leaving.NET So far, the lesson has covered theoretical aspects of the.net architecture Only a few things of what we covered have practical implications Garbage collector The possibility to interact between.net languages The rest of this lecture will be more practical!
, 9 Namespaces We start with namespaces! Divided into layers hierarchically divided by period, like System.IO Code in different files can belong to the same namespace Use is optional Except for components Helps avoid name clashes Namespaces using removes need to type full namespace name using System; makes it possible to for instance access Console.WriteLine(); without spelling out System.Console.WriteLine(); Namespaces namespace x.y { class Slask { } } // is shorthand for writing namespace x { } namespace y { class Slask { } } If one wants to use class Slask from another namespace the namespace must be addressed Either: using x.y; Slask s=new Slask(); or: x.y.slask s=new x.y.slask();
, 10 Boxing Enables conversion from value type to reference type Unboxing does the reverse, converting from reference box to value type Boxing implies making a copy of the value int i = 123; object box = i; if(box is int) // box contains an int int y = (int) box; // y contains int value // contained in box 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 volatile while Visual Studio Graphical environment (IDE) for developing.net-applications Microsoft Syntax highlighting Code completion GUI designer drag n drop, very easy to use, supernice Easy handling of events
, 11 Visual Studio competitors.net is standardized C# is also standardized Other compilers and environments exist e.g. Mono for Linux Visual Studio (cont d) VS starting a new project
, 12 VS starting (cont d) VS editing VS handling events
, 13 VS connecting stuff VS -finito