123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AnonymousTypes { class Program { static void Main(string[] args) { // implicitly creating class, only for LINQ // in normal situation create classes normally var myCar = new { Color = "Bright", Make = "Saab", Speed = 55 }; Console.WriteLine("My car is a {0} {1}",myCar.Color,myCar.Make); ReflectAnonymousType(myCar); PrintValueAndAdresses(); Console.ReadLine(); } static void ReflectAnonymousType(object obj) { Console.WriteLine("obj is an instance of {0}:",obj.GetType().Name); // continued in Troelsen, p. 452 } unsafe static void PrintValueAndAdresses() { int i; int* ptrToMyInt = &i; *ptrToMyInt = 123; Console.WriteLine("Value of i {0}",i); Console.WriteLine("Adress of ptrToMyInt {0}", (int)&ptrToMyInt); } } } |