Tech Talk – C# und das Microsoft .NET Framework Heinrich Wendel, DLR Simulations- und Softwaretechnik 30. Juli 2008
Entstehungsgeschichte <ul><li>Microsofts Dominanz der PC-Kerntechnologien in Gefahr  </li></ul><ul><li>Wunsch nach konkurr...
History <ul><li>2000: Bill Gates stellt die .NET- „Vision“ vor </li></ul><ul><li>2002: .NET (V1.0) mit SDK wird vorgestell...
Architektur
Common Language Infrastructure <ul><li>Common Language Specification </li></ul><ul><ul><li>Minimales Set an Features zur K...
Interoperabilität
Assemblies <ul><li>Bibliothek enthält CIL Code, Dateitype .dll / .exe </li></ul><ul><ul><li>Name </li></ul></ul><ul><ul><l...
Dynamic Assembly loading <ul><li>Assemblies können dynamisch zur Laufzeit geladen aber nicht entladen werden </li></ul><ul...
C# - Namespaces // Defining namespaces namespace  Dlr.Sistec { class Test { … } } // Nested namespaces namespace  Dlr { na...
C# - Control Flow <ul><li>Iteration </li></ul><ul><ul><li>For </li></ul></ul><ul><ul><li>Foreach </li></ul></ul><ul><ul><l...
C# - Iterators Months months = new Months();  foreach (string temp in months)    Console.WriteLine(temp);  public class Mo...
C# - Switch / Enums string s = Console.ReadLine();; switch(s) { case „ January “:  … break; case „ Februar “:  … break; ca...
C# - Switch / Enums <ul><li>public  Enum  Month { </li></ul><ul><ul><li>January = 1, </li></ul></ul><ul><ul><li>Februar = ...
C# - Switch / Enums [Flags]  public enum Keys {  Shift = 1,  Ctrl = 2,  Alt = 4  } Keys k = Keys.Shift | Keys.Ctrl if ((k ...
C# - Indexer String[] People = { „Schreiber, „Legenhausen“, „Wendel“}; Console.Write( People[0] ) People[1]  = Console.Rea...
C# - Properties public class Person { private string  firstName ; private string  lastName ; public void  setFirstName (st...
C# - Attributes <ul><li>Annotations in Java / Decorators in Python </li></ul><ul><li>Anwendbar auf Assemblies, Klassen, Me...
C# - Attributes [AttributeUsage(AttributeTargets.All)]  public class DeveloperAttribute :  Attribute  {  public string Zun...
C# - Delegates / Events public class Logger { public  delegate  void Log(string message); private  static  Log  log ger ; ...
C# - Lambda Funktionen public class Logger {  public delegate void Log(string message); private static Log logList; public...
<ul><li>Queries auf IEnumerable<T>, Relationale Datenbanken, XML Dateien </li></ul><ul><li>from, in, where, select, join, ...
C# - Structs <ul><li>Fast alle Features einer Klasse </li></ul><ul><li>Keine Vererbung </li></ul><ul><li>Value Types statt...
C# - Constructors public class Point { public Point(int x, int y) { X = x; Y = y; } public Point() { } public int X { get;...
C# - Constructors public class Point { public int X { get; set; } public int Y { get; set; } } public class Rectangle { pu...
C# - Unsafe Code <ul><li>Erlaubt Pointer-Operationen </li></ul><ul><li>unsafe keyword </li></ul><ul><li>Höhere Performance...
C# - Preprocessor <ul><li>#define / #undef </li></ul><ul><li>#if / #else / #elif / #endif </li></ul><ul><li>#region / #end...
C# - Exception Handling <ul><li>try / catch / finally </li></ul><ul><li>Python like statt Java like </li></ul><ul><ul><li>...
C# - Method Calls void FunctionA( ref  int Val) { int x= Val;  Val = x* 4;  } int a= 5; FunctionA( ref  a); Console.WriteL...
C# - Extension Methods public  static  class  ExtensionClass  { public  static  int MultiplyByTwo( this int number) { retu...
C# - Casting object [] myObjects = new object[1] myObjects[0] = new MyClass1(); string s; // Exception s = (string) myObje...
C# - Keywordmania <ul><li>sealed </li></ul><ul><li>internal / protected internal </li></ul><ul><li>const </li></ul><ul><li...
C# - Was sonst noch geht … <ul><li>Generics </li></ul><ul><li>Operatoren überladen </li></ul><ul><ul><li>Strings können mi...
Library <ul><li>Isolated Storage </li></ul><ul><li>ADO.NET </li></ul><ul><li>Windows Communication Foundation </li></ul><u...
Parallel Programming <ul><li>Builtin Mechanisms: </li></ul><ul><ul><li>Locks </li></ul></ul><ul><ul><li>Monitors </li></ul...
Entwicklungsumgebungen <ul><li>Microsoft Visual Studio </li></ul><ul><ul><li>Express </li></ul></ul><ul><ul><li>Standard <...
Tools <ul><li>Nunit </li></ul><ul><li>Ndoc </li></ul><ul><li>FxCop </li></ul><ul><li>Lutz Roeder's Reflector </li></ul><ul...
Lizenzen <ul><li>CLI und C#: ECMA Standard </li></ul><ul><ul><li>VM (CIL) </li></ul></ul><ul><ul><li>C# Compiler </li></ul...
Alternative .NET Implementierungen <ul><li>Mono </li></ul><ul><li>DotGNU </li></ul><ul><li>CrossNet (Assemblies to Unmanag...
IKVM.NET <ul><li>Java für .NET </li></ul><ul><li>Java Virtual Machine </li></ul><ul><li>.NET implementation der Java Klass...
IronPython <ul><li>Implementiernug von Python für .NET </li></ul><ul><li>Keine C-Extensions (e.g. NumPy) </li></ul><ul><ul...
 
Upcoming SlideShare
Loading in...5
×

TechTalk - Dotnet

1,405

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,405
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Coding Guidelines Sprache
  • TechTalk - Dotnet

    1. 1. Tech Talk – C# und das Microsoft .NET Framework Heinrich Wendel, DLR Simulations- und Softwaretechnik 30. Juli 2008
    2. 2. Entstehungsgeschichte <ul><li>Microsofts Dominanz der PC-Kerntechnologien in Gefahr </li></ul><ul><li>Wunsch nach konkurrenzfähiger Technik „gegen Java“ </li></ul><ul><li>Alte, nicht zueinander kompatible Windows Technologien ersetzen </li></ul>
    3. 3. History <ul><li>2000: Bill Gates stellt die .NET- „Vision“ vor </li></ul><ul><li>2002: .NET (V1.0) mit SDK wird vorgestellt </li></ul><ul><li>2003: .NET 1.1 und Visual Studio 2003 </li></ul><ul><li>2005: Release des .NET Framework 2.0 und Visual Studio 2005 </li></ul><ul><li>2006: .Net Framework 3.0 verfügbar </li></ul><ul><li>2007: .NET 3.5 und Visual Studio 2008 </li></ul>
    4. 4. Architektur
    5. 5. Common Language Infrastructure <ul><li>Common Language Specification </li></ul><ul><ul><li>Minimales Set an Features zur Kompatibilität zwischen Sprachen </li></ul></ul><ul><ul><li>[ClsCompliant(true)] </li></ul></ul><ul><li>Beispiel </li></ul><ul><ul><li>Pointer </li></ul></ul><ul><ul><li>unsigned Typen </li></ul></ul><ul><ul><li>Groß/Kleinschreibung </li></ul></ul><ul><li>Common Type System </li></ul>
    6. 6. Interoperabilität
    7. 7. Assemblies <ul><li>Bibliothek enthält CIL Code, Dateitype .dll / .exe </li></ul><ul><ul><li>Name </li></ul></ul><ul><ul><li>Version </li></ul></ul><ul><ul><li>Kultur (Satellite assemblies) </li></ul></ul><ul><ul><li>Public Key (Strong name) </li></ul></ul><ul><li>Global Assembly Cache </li></ul><ul><li>Eingebettete Resourcen </li></ul><ul><li>Manifest </li></ul>
    8. 8. Dynamic Assembly loading <ul><li>Assemblies können dynamisch zur Laufzeit geladen aber nicht entladen werden </li></ul><ul><li>Application Domains (vgl. OSGi) </li></ul><ul><ul><li>Abgetrennte Bereiche </li></ul></ul><ul><ul><li>Sicherheit </li></ul></ul><ul><ul><li>Konfiguration </li></ul></ul><ul><ul><li>ExceptionHandling </li></ul></ul><ul><ul><li>Können gestartet und gestoppt werden </li></ul></ul><ul><ul><li>Kommunikation über .NET Remoting </li></ul></ul>
    9. 9. C# - Namespaces // Defining namespaces namespace Dlr.Sistec { class Test { … } } // Nested namespaces namespace Dlr { namespace Sistec { class Test {…} } } // Using namespaces Dlr.Sistec.Test = new Dlr.Sistec.Test(); // Short form Using Dlr.Sistec; Test = new Test(); // Aliases Using ns = Dlr.Sistec; ns.Test = new ns.Test();
    10. 10. C# - Control Flow <ul><li>Iteration </li></ul><ul><ul><li>For </li></ul></ul><ul><ul><li>Foreach </li></ul></ul><ul><ul><li>While </li></ul></ul><ul><ul><li>Do…While </li></ul></ul><ul><li>Kontrollstrukturen </li></ul><ul><ul><li>If/else if/else </li></ul></ul><ul><ul><li>Kurzfassung: Bedingung ? Anweisung1 : Anweisung2 </li></ul></ul><ul><ul><li>Switch </li></ul></ul>
    11. 11. C# - Iterators Months months = new Months(); foreach (string temp in months) Console.WriteLine(temp); public class Months : IEnumerable {   string[] month = { &quot;Januar&quot;, &quot;Februar&quot;, &quot;März&quot;, &quot;April&quot;, &quot;Mai&quot;, &quot;Juni&quot;, &quot;Juli&quot;, &quot;August&quot;, &quot;September&quot;, &quot;Oktober&quot;, &quot;November&quot;, &quot;Dezember&quot;};   public IEnumerator GetEnumerator() {     for (int i = 0; i < month.Length; i++)       yield return month[i];   } }
    12. 12. C# - Switch / Enums string s = Console.ReadLine();; switch(s) { case „ January “: … break; case „ Februar “: … break; case „ March “: … break; … }
    13. 13. C# - Switch / Enums <ul><li>public Enum Month { </li></ul><ul><ul><li>January = 1, </li></ul></ul><ul><ul><li>Februar = 2, </li></ul></ul><ul><ul><li>March = 3 </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>} </li></ul>Month m = …; switch (m) { case Month.January : break; case Month.February : break; case 3 : break; … }
    14. 14. C# - Switch / Enums [Flags] public enum Keys { Shift = 1, Ctrl = 2, Alt = 4 } Keys k = Keys.Shift | Keys.Ctrl if ((k & Keys.Shift) == Keys.Shift) {…}
    15. 15. C# - Indexer String[] People = { „Schreiber, „Legenhausen“, „Wendel“}; Console.Write( People[0] ) People[1] = Console.ReadLine() <ul><li>public dataType this[int index] </li></ul><ul><li>{ </li></ul><ul><li>get </li></ul><ul><li>{ </li></ul><ul><ul><li>/// … </li></ul></ul><ul><li>} </li></ul><ul><li>set </li></ul><ul><li>{ </li></ul><ul><ul><li>/// … </li></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    16. 16. C# - Properties public class Person { private string firstName ; private string lastName ; public void setFirstName (string name) this.firstName = name; } public string getLastName () return this.lastName; } public void setLastName (string name) this.lastName = name } public string getFirstName () return this.firstName; } } public class Person { public string FirstName { get { return firstName; } set { firstName = value ; } } private string firstName ; public string LastName { get { return lastName; } set { lastName = value ; } } private string lastName ; } Public class Person { public string FirstName { get; set ; } public string LastName { get; set ; } }
    17. 17. C# - Attributes <ul><li>Annotations in Java / Decorators in Python </li></ul><ul><li>Anwendbar auf Assemblies, Klassen, Methoden, Felder … </li></ul><ul><li>Vordefinierte Attribute </li></ul><ul><ul><li>[Serializable] </li></ul></ul><ul><ul><li>[ClsCompliant(true)] </li></ul></ul><ul><ul><li>[Obsolete] </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Eigene Attribute </li></ul>
    18. 18. C# - Attributes [AttributeUsage(AttributeTargets.All)] public class DeveloperAttribute : Attribute { public string Zuname; public int PersID; public DeveloperAttribute(string name) { Zuname = name; } } [DeveloperAttribute(&quot;Meier&quot;, PersID = 8815)] class Program { static void Main(string[] args) { DeveloperAttribute attr = (DeveloperAttribute)Attribute. GetCustomAttribute(typeof(Program), typeof(DeveloperAttribute)); Console.WriteLine(&quot;Name: {0}&quot;, attr.Zuname ); Console.WriteLine(&quot;PersID: {0}&quot;, attr.PersID ); }
    19. 19. C# - Delegates / Events public class Logger { public delegate void Log(string message); private static Log log ger ; public static void Main(string[] args) { log ger = new Log(PrintToConsole); log ger.Invoke (&quot;message&quot;); } public static void PrintToConsole(string message) { Console.WriteLine(message); } } public class Logger { public delegate void Log(string message); private static Log logList; public static void Main(string[] args) { logList += new Log(PrintToConsole); logList += new Log(PrintTo File ); logList (&quot;message&quot;); } public static void PrintToConsole (string message) { … } public static void PrintTo File (string message) { … } } public class Logger { public delegate void Log(string message); public static event Log logList ; public static void Main(string[] args) { logList += PrintToConsole; logList += PrintTo File ; logList (&quot;message&quot;); } public static void PrintToConsole (string message) { … } public static void PrintTo File (string message) { … } }
    20. 20. C# - Lambda Funktionen public class Logger { public delegate void Log(string message); private static Log logList; public static void Main(string[] args) { logList = delegate(string message) { Console.WriteLine(message); }; logList(&quot;message&quot;); } } public class Logger { public delegate void Log(string message); private static Log logList; public static void Main(string[] args) { logList = message => { Console.WriteLine(message); }; logList(&quot;message&quot;); } } List <int> evenNumbers = list.FindAll( i => (i%2) == 0 );
    21. 21. <ul><li>Queries auf IEnumerable<T>, Relationale Datenbanken, XML Dateien </li></ul><ul><li>from, in, where, select, join, on, equals, into, orderby, ascending, descending, group, by </li></ul>C# - LINQ int[] numbers = { 10, 20, 30, 40, 1, 2, 3, 8 }; var subset = from i in numbers where i < 10 select i ; foreach (int i in subset) Console.WriteLine(i);
    22. 22. C# - Structs <ul><li>Fast alle Features einer Klasse </li></ul><ul><li>Keine Vererbung </li></ul><ul><li>Value Types statt Reference Types </li></ul>public struct Point { int x {get; set} int y {get; set} public Point(int x, int y) { … } public int getDistance(int x, int y) { … } public static Point operator +(Point p) {…} }
    23. 23. C# - Constructors public class Point { public Point(int x, int y) { X = x; Y = y; } public Point() { } public int X { get; set; } public int Y { get; set; } } Point p = new Point(1, 2) Point p = new Point() P.X = 1; p.Y = 2; Point p = new Point { X = 1, Y = 2 }
    24. 24. C# - Constructors public class Point { public int X { get; set; } public int Y { get; set; } } public class Rectangle { public Point topLeft { get; set; } public Point bottomRight { get; set; } } Rectangle r = new Rectangle { topLeft = new Point{ X = 0, Y = 0 }, bottomRight = new Point { X = 2, Y = 2 } } Rectangle r = new Rectangle(); Point p1 = new Point(); p1.X = 0; p1.Y = 0; Point p2 = new Point(); p2.X = 2; p2.Y = 2; r.topLeft = p1; r.bottomRight = p2;
    25. 25. C# - Unsafe Code <ul><li>Erlaubt Pointer-Operationen </li></ul><ul><li>unsafe keyword </li></ul><ul><li>Höhere Performance </li></ul><ul><li>Fixed keyword </li></ul>int var1 = 5; unsafe { int * ptr1, ptr2; ptr1 = & var1; ptr2 = ptr1; *ptr2 = 20; } Console.WriteLine(var1);
    26. 26. C# - Preprocessor <ul><li>#define / #undef </li></ul><ul><li>#if / #else / #elif / #endif </li></ul><ul><li>#region / #endregion </li></ul>
    27. 27. C# - Exception Handling <ul><li>try / catch / finally </li></ul><ul><li>Python like statt Java like </li></ul><ul><ul><li>Exceptions müssen nicht gefangen und deklariert werden! </li></ul></ul><ul><ul><li>Nicht mehrere in einem catch-Block behandelbar </li></ul></ul><ul><li>Exception Klasse </li></ul><ul><ul><li>TargetSite </li></ul></ul><ul><ul><li>StackTrace </li></ul></ul><ul><ul><li>HelpLink </li></ul></ul><ul><ul><li>Data </li></ul></ul><ul><li>Eigene Exceptions sollen von ApplicationException ableiten </li></ul><ul><ul><li>SystemException </li></ul></ul><ul><ul><ul><li>IndexOutOfRangeException </li></ul></ul></ul><ul><ul><ul><li>NullReferenceException </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul>
    28. 28. C# - Method Calls void FunctionA( ref int Val) { int x= Val; Val = x* 4; } int a= 5; FunctionA( ref a); Console.WriteLine(a); bool GetNodeValue( out int Val) { Val = 1; return true; } int Val; GetNodeValue(Val); Console.WriteLine(a); void Func(params int[] array) { Console.WriteLine(array.Length); } Func(1); Func(7,9); Func(new int[] {3,8,10});
    29. 29. C# - Extension Methods public static class ExtensionClass { public static int MultiplyByTwo( this int number) { return number * 2; } } public class Class1 { public static void Main(string[] args) { int number = 2; Console.WriteLine( number.MultiplyByTwo() ); } }
    30. 30. C# - Casting object [] myObjects = new object[1] myObjects[0] = new MyClass1(); string s; // Exception s = (string) myObjects[0] public static explicit operator String(MyClass1) { return “SomeString”; } If (myObjects[0] is string) { s = (string) myObjects[1] } s = myObjects[0] as string
    31. 31. C# - Keywordmania <ul><li>sealed </li></ul><ul><li>internal / protected internal </li></ul><ul><li>const </li></ul><ul><li>readonly </li></ul><ul><li>this / base </li></ul><ul><li>nullable (?) </li></ul><ul><li>partial </li></ul><ul><li>(un)checked </li></ul><ul><li>abstract / virtual / override / new </li></ul>
    32. 32. C# - Was sonst noch geht … <ul><li>Generics </li></ul><ul><li>Operatoren überladen </li></ul><ul><ul><li>Strings können mit == übeprüft werden </li></ul></ul><ul><li>Auto(un)boxing </li></ul><ul><li>Eigene Listen (System.Collecions / System.Collections.Generic) </li></ul><ul><li>Sortierung (IComparable / ICompare) </li></ul><ul><li>String formatierung (String.Format) </li></ul>
    33. 33. Library <ul><li>Isolated Storage </li></ul><ul><li>ADO.NET </li></ul><ul><li>Windows Communication Foundation </li></ul><ul><li>Windows Workflow Foundation </li></ul><ul><li>Windows Forms </li></ul><ul><li>Windows Presentation Foundation </li></ul>
    34. 34. Parallel Programming <ul><li>Builtin Mechanisms: </li></ul><ul><ul><li>Locks </li></ul></ul><ul><ul><li>Monitors </li></ul></ul><ul><ul><li>synchronisation keyword </li></ul></ul><ul><ul><li>Threads </li></ul></ul><ul><li>ParallelFX </li></ul><ul><ul><li>Parallel.For </li></ul></ul><ul><li>LINQ per default parallelisiert </li></ul>
    35. 35. Entwicklungsumgebungen <ul><li>Microsoft Visual Studio </li></ul><ul><ul><li>Express </li></ul></ul><ul><ul><li>Standard </li></ul></ul><ul><ul><li>Professional </li></ul></ul><ul><ul><li>Team System (Architecture-, Database-, Development-, Test- Edition) </li></ul></ul><ul><li>(http://msdn.microsoft.com/de-de/vs2008/cc149003.aspx) </li></ul><ul><li>SharpDevelop </li></ul><ul><li>MonoDevelop </li></ul>
    36. 36. Tools <ul><li>Nunit </li></ul><ul><li>Ndoc </li></ul><ul><li>FxCop </li></ul><ul><li>Lutz Roeder's Reflector </li></ul><ul><li>NAnt </li></ul>
    37. 37. Lizenzen <ul><li>CLI und C#: ECMA Standard </li></ul><ul><ul><li>VM (CIL) </li></ul></ul><ul><ul><li>C# Compiler </li></ul></ul><ul><ul><li>Neue Sprachen </li></ul></ul><ul><li>Klassenbibliotheken und andere Teile: shared source </li></ul><ul><ul><li>WindowsForms </li></ul></ul><ul><ul><li>ADO.NET </li></ul></ul><ul><ul><li>ASP.NET </li></ul></ul>
    38. 38. Alternative .NET Implementierungen <ul><li>Mono </li></ul><ul><li>DotGNU </li></ul><ul><li>CrossNet (Assemblies to Unmanaged C++) </li></ul><ul><li>.NET for Symbian </li></ul><ul><li>Shared Source Common Language Infrastructure (MS) </li></ul>
    39. 39. IKVM.NET <ul><li>Java für .NET </li></ul><ul><li>Java Virtual Machine </li></ul><ul><li>.NET implementation der Java Klassenbibliothek </li></ul><ul><li>Tools um Java und .NET Programme zu verbinden </li></ul><ul><li>Java Bytecode in einer JVM auf der CLR laufen lassen </li></ul><ul><li>Java in CLI compilieren </li></ul><ul><li>Noch kein AWT/Swing </li></ul>
    40. 40. IronPython <ul><li>Implementiernug von Python für .NET </li></ul><ul><li>Keine C-Extensions (e.g. NumPy) </li></ul><ul><ul><li>Ironclad </li></ul></ul><ul><li>Dynamic Language Runtime </li></ul><ul><ul><li>Dynamic Type System </li></ul></ul><ul><ul><li>JScript </li></ul></ul><ul><ul><li>VBx </li></ul></ul><ul><li>Integration in Silverlight Applikationen </li></ul>

    ×