Beispiel #1
0
        static void Main(string[] args)
        {
            //int x = 3;
            //int y = 4;
            //int z = 5;
            //int result = x *= y += z;
            //Console.WriteLine(result);

            //Program p = new Program();
            //Console.WriteLine(p.Hanoi(8)-1);

            //int x = 10;
            //Console.WriteLine(x.GetType());

            //do
            //{
            //    Console.WriteLine(x);
            //    x--;
            //}
            //while (x > 0);

            //var x = 3;
            //Console.WriteLine(x.GetType());

            //var y = new { name = "marchi", age = 26 };
            //Console.WriteLine(y.GetType().FullName);
            //Console.WriteLine(y.GetType());

            //Console.WriteLine("Helloworld");
            //Form form1 = new Form();
            //Form form2 = form1;
            //form1.Text = "test";
            //form2.Text = "test2";
            //form1.ShowDialog();
            //form2.ShowDialog();

            //for(int num=1; num < 10;num++){
            //    Console.WriteLine(num);
            //}

            //int[] array = new int[]{ 1,2,3,4,5};
            //Console.WriteLine(array[1]);

            //Form myForm = default(Form);
            //Console.WriteLine(myForm == null);
            unsafe
            {
                //Student stu;
                //Student* pStu = &stu;
                //pStu->score = 3;
                //Console.WriteLine(pStu->score);
                //Console.WriteLine(stu.score);
                //(*pStu).score = 4;
                //Console.WriteLine((*pStu).score);
                //int x = sizeof(Student);
                //Student stu;
                //stu.score = 2;
                //Console.WriteLine(stu.score);
                //Student.ID = 1;
            }
            //Human h = new Human();
            //Teacher t = h;
            //t.Teach();

            //uint y = 65537;
            //ushort x = (ushort)y;
            //Console.WriteLine(x);

            //char z= char.MaxValue;
            //Console.WriteLine(z);
            //Console.WriteLine(z.GetType());
            //Console.WriteLine(Convert.ToInt32(z));

            //int counter = 0;
            //for (counter = 0; counter < 10; ++counter)
            //{
            //    Console.WriteLine("Helloworld");
            //}
            //Console.WriteLine(counter);

            //int[] intArray = new int[] { 1, 2, 3, 4, 5, 6 };
            //IEnumerator enumerator = intArray.GetEnumerator();
            //while (enumerator.MoveNext())
            //{
            //    Console.WriteLine(enumerator.Current);
            //}

            //List<Student> stuList = new List<Student>();
            //for (int i = 0; i < 100; i++)
            //{
            //    Student stu = new Student();
            //    stu.Age += 40;
            //    stu.Score = i;
            //    stuList.Add(stu);
            //}
            //    int totalAge=0;
            //    int totalScore=0;
            //    foreach (var stu in stuList)
            //    {
            //        totalAge += stu.Age;
            //        totalScore += stu.Score;
            //    }
            //    Student.AverageAge = totalAge / Student.Amount;
            //    Student.AverageScore = totalScore / Student.Amount;
            //    Student.ReportAmount();
            //    Student.ReportAverageAge();
            //    Student.ReportAverageScore();

            //public long Hanoi(int x)
            //{
            //    if (x == 1)
            //    {
            //        return 2;
            //    }
            //    else
            //    {
            //        long result = 2 * Hanoi(x - 1);
            //        return result;
            //    }
            //}

            //try
            //{
            //    Student2 stu1 = new Student2();
            //    stu1.Age = 20;
            //    Console.WriteLine(stu1.CanWork);
            //    Student2 stu2 = new Student2();
            //    stu2.Age = 10;

            //    //Console.WriteLine(stu1.Age+stu2.Age);
            //    if (stu2.Age >0&& stu2.Age <100)
            //    {
            //        Console.WriteLine(stu1.Age);
            //        int x = 100;
            //        stu1.Age = 15;
            //    }
            //    Console.WriteLine(stu1.Age);
            //    //Console.WriteLine(x);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            //17 chapter indexer example
            //try
            //{
            //    Indexer index1 = new Indexer();
            //    var scoreMath = index1["Math"];

            //}catch(Exception ex)
            //{
            //    Console.WriteLine(ex);
            //}

            //18 chapter out argument
            //try
            //{
            //    bool b = Staff.StaffFactory("19", "Joe", out Staff st1);
            //    if (b == true)
            //    {
            //        Console.WriteLine("Name={0},Age={1}", st1.Name, st1.Age);
            //    }
            //    else
            //    {
            //        Console.WriteLine(b);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            //18 chapter value&ref argument
            //Employee em1 = new Employee();
            //Student stu1 = new Student();
            //stu1.Age = 20;
            //Console.WriteLine("{0}-{1}",stu1.GetHashCode(),stu1.Age);
            //em1.NewEmpolyee(ref stu1);
            //Console.WriteLine("{0}-{1}",stu1.GetHashCode(),stu1.Age);

            //18 chapter params argument
            //Employee em2 = new Employee();
            //int x =em2.ShowAge("12","24", "Tim");
            //Console.WriteLine(x);

            //19 chapter delegate template method
            //ProductFactory productFactory = new ProductFactory();
            //WrapFactory wrapFactory = new WrapFactory();
            ////Func<Product> fun1 = new Func<Product>(productFactory.PizzaFactory);
            ////Func<Product> fun2 = new Func<Product>(productFactory.ToyCarFactory);
            //Box box1 = wrapFactory.WarpFactory(productFactory.PizzaFactory);
            //Box box2 = wrapFactory.WarpFactory(productFactory.ToyCarFactory);
            //Console.WriteLine(box1.Product.Name);
            //Console.WriteLine(box2.Product.Name);

            //19 chapter delegate bad quality code
            //Operation op1 = new Operation();
            //Operation op2 = new Operation();
            //Operation op3 = new Operation();
            //op3.innerOperation = op2;
            //op2.innerOperation = op1;
            //op3.Operate(new object(), null, null);
            //Myform myform = new Myform();
            //myform.ShowDialog();

            //22 chapter custom event problem
            //Methor x = new Methor(Delegatetset.Test);
            //x.Invoke(1, 2);

            //22 chapter custom event problem(customer)
            //Customer customer = new Customer();
            //Waiter waiter = new Waiter();
            //customer.Order += waiter.Action;
            //customer.Action();
            //customer.PayTheBill();
            //Console.ReadLine();

            //24 chapter Class declare,Accessibility levels
            //Class1 class1 = new Class1();
            //Console.WriteLine(class1.Add(1,2));

            //25 Parent class,Child class and Base class,Derived class
            //Vehicle c1 = new Car("James");
            //Console.WriteLine(c1.Owner);
            //c1.Run();
            //Console.WriteLine(c1.Owner);

            //int a = 12;
            ////Console.WriteLine(a.GetType().IsValueType);
            //Mathod1 mathod = new Mathod1((new ModifierTest()).Main_Mod);
            //mathod.Invoke();
            //Console.WriteLine(mathod.GetType().IsClass);
            ////object b = a;
            ////object b = new object();
            //string b = "0";
            //Console.WriteLine(b);
            //Console.WriteLine(b.GetType().IsClass);
            //Console.WriteLine(b.GetType().IsValueType);

            //30 chapter Generic delegate,Lambda expression,LINQ
            //var deleMod_ex = new DeleMod_ex();
            //deleMod_ex.Result();
            //Method_Parameter.CreateOrigin();
            //26 chapter override and polymorphism
            Animal T1 = new Teacher();

            T1.Run();
            //27 abstract class and open-close principle
            //VehicleAbstract car = new Race();
            //car.Run();
            //28 interface,dependency inversion,unit test
            //Driver Linda = new Women(new Race());
            //Linda.Drive();
            //29 instence segregation,reflection,attribute,dependency injection
            //Driver mark = new Men(new MediumTank(),123) { Age = 1 };
            //Driver driver = mark;
            //driver.Age = 2;
            //Console.WriteLine(mark.Age);

            //Mark.Drive();
            //30 generic,partial class,enum,struct
            //Action<int,int> action = DeleMod_ex.Action_exp;
            Men joe = new Men(new LightTank(), 123);

            Console.WriteLine(joe.Age);
            decimal test = 1.1m;

            //ex001 generic delegate,lambda expression,linq
            Test <double, int> test1 = new Test <double, int>(Test);

            Console.WriteLine(test1.Invoke(1, 2));
        }