static void Dynamo() { //dynamics werden erst zur Laufzeit einem Typ zugeordnet dynamic dyn = 1; dynamic dyn2 = new SimpleStructure(1, "Harald"); object obj = 1; var var = 1; Console.WriteLine("dyn: {0}", dyn.GetType()); Console.WriteLine("dyn2: " + dyn2.GetType()); Console.WriteLine("obj: " + obj.GetType()); Console.WriteLine("var: " + var.GetType()); }
static void KeepItSafe() { //Compiler uebernimmt Typenzuordnung, falls eindeutig string[] words = { "apple", "strawberry", "grape" }; var wordQuery = from word in words where word[0] == 'g' select word; //Aequivalent mit dem oberen Code IEnumerable <string> same = from word in words where word[0] == 'g' select word; SimpleStructure one = new SimpleStructure(1, ""); SimpleStructure two = new SimpleStructure(2, ""); SimpleStructure three = new SimpleStructure(3, ""); SimpleStructure four = new SimpleStructure(4, ""); SimpleStructure[] structures = { one, two, three, four }; //var keyword notwendig, da der Compiler bei anonymen Klassen nicht den Typ kennt var wordQueryTwo = from s in structures where s.Method() == 2 select new { s.name }; }