static void Main(string[] args) { Console.WriteLine("Chap1"); Console.WriteLine(AppDomain.CurrentDomain.FriendlyName); //Lession 1: value types double d1 = 2.5; int i1 = 5555; int i2 = i1; i1 = 22; Console.WriteLine("i1 = {0}", i1); Console.WriteLine("i2 = {0}", i2); string s1 = "spam"; object o1, o2, o3; o1 = d1; o2 = i1; o3 = s1; Console.WriteLine(o1.GetType().FullName); Console.WriteLine(o2.GetType().FullName); Console.WriteLine(o3.GetType().FullName); bool b1 = true; bool? b2 = true; Nullable <bool> b3 = new Nullable <bool>(); Console.WriteLine("bool b1 is:{0}", b1.ToString()); Console.WriteLine("bool b3 is null? {0}", b3 == null); Console.WriteLine("bool b2 is null? {0}", b2 == null); Console.WriteLine("bool b2 has a value? {0}", b2.HasValue.ToString()); Console.WriteLine("Bool b3 has a value? {0}", b3.HasValue.ToString()); ValChange v = new ValChange(); v.Date = DateTime.Now; v.Value = 5.4432; Console.WriteLine("ValChange v =:" + v.ToString()); //enums TestEnum te = TestEnum.Frau; Console.WriteLine("Test enum is equal to Mau:{0}", te == TestEnum.Mau); //strings & string builders string s2, s3, s4; s1 = "matt"; s2 = "test"; s3 = "spam"; s3.Replace("pa", "ki"); s4 = s1; s1 = "abby"; Console.WriteLine("string s1=" + s1); Console.WriteLine("string s2=" + s2); Console.WriteLine("string s3=" + s3); Console.WriteLine("string s4=" + s4); StringBuilder sb = new StringBuilder(); sb.Append(s1); sb.Append(" | "); sb.Append(s2); sb.Append(" | "); sb.Append(s3); sb.Append(" | "); sb.Append(s4); Console.WriteLine("String builder sb:" + sb.ToString()); sb.Replace("pa", "ki"); Console.WriteLine("String builder sb:" + sb.ToString()); //arrays int[] ar = { 3, 2, 1 }; Array.Sort(ar); Console.WriteLine("{0}, {1}, {2}", ar[0], ar[1], ar[2]); //streams System.IO.StreamWriter sw = new System.IO.StreamWriter("text.txt"); sw.WriteLine("Hello Totalflow!"); sw.Close(); System.IO.StreamReader sr = new System.IO.StreamReader("text.txt"); Console.WriteLine(sr.ReadToEnd()); sr.Close(); //exceptions try { throw new TFBigException(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } try { throw new TFException(); } catch (TFBigException ex1) { Console.WriteLine(ex1.ToString()); } catch (TFException ex2) { Console.WriteLine(ex2.ToString()); } //inheritance Test1 t1 = new Test2(); Console.WriteLine(t1.ToString()); Console.WriteLine(t1.foobar().ToString()); //interface Test3 t3 = new Test3(); IComparable t3i = t3; Console.WriteLine("T3 IComparable interface:{0}", t3i.CompareTo(new object())); Test2 t2 = new Test2(); Console.WriteLine("T2 IComparable interface v1:{0}", t2.CompareTo(new Test2())); IComparable t2i = t2; Console.WriteLine("T2 IComparable interface v2:{0}", t2i.CompareTo(new Test2())); //partial classes //generics List <DateTime> ldt = new List <DateTime>(); ldt.Add(new DateTime(2005, 12, 11)); ldt.Add(new DateTime(2006, 4, 25)); Console.WriteLine("generic list ldt contains 1/1/2222:" + ldt.Contains(new DateTime(2222, 1, 1)).ToString()); Console.WriteLine("generic list ldt contains 4/25/2006:" + ldt.Contains(new DateTime(2006, 4, 25)).ToString()); Console.WriteLine("Generic method MyGenMethod {0}", MyGenMethod <Test3>(t3).ToString()); Gen1 <Test3, ValChange> g1 = new Gen1 <Test3, ValChange>(t3, v); Console.WriteLine("Generic class g1 to string:" + g1.ToString()); //events GetMessage += new MyDelegate(Program_GetMessage); Console.WriteLine("Getmessage returns {0}", GetMessage("Here we are!")); GetMessage += new MyDelegate(Program_GetMessage1); Console.WriteLine("Getmessage returns {0}", GetMessage("Here we are!")); //attributes //type forwarding //conversion //boxing & unboxing //conversion implmentation MyInt a1; a1.Value = 44; Int64 i64 = Convert.ToInt64(a1); b1 = Convert.ToBoolean(a1); MyIntStruct a; int b; a = 45; b = (int)a; Console.WriteLine("a = {0} , b ={1}", a.ToString(), b.ToString()); }