Esempio n. 1
0
        //static void Main(string[] args)
        //{
        //    int[] scores = { 17, 46, 39, 62, 81, 79, 52, 24, 49 };
        //    Chapter1 ch1 = new Chapter1();
        //    int threshold = 40;
        //    var (average, studentCount, belowAverage) = ch1.GetAverageAndCount(scores, threshold);
        //    WriteLine($"Average was {Round(average, 2)} accross {studentCount} students. {(average < threshold ? "1" : "2")}");
        //    ReadLine();
        //}
        #endregion

        #region 3.0 Pattern Matching
        //static void Main(string[] args)
        //{
        //    Chapter1 ch1 = new Chapter1();
        //    Student student = new Student();
        //    student.Name = "John";
        //    student.LastName = "Kirk";
        //    student.CourseCodes = new List<int> { 203, 202, 101 };
        //    ch1.OutputInfomation(student);
        //    Professor professor = new Professor();
        //    professor.Name = "Luke";
        //    professor.LastName = "Lucky";
        //    professor.TeacherSubject = new List<string> { "Math", "English" };
        //    ch1.OutputInfomation(professor);
        //    ReadLine();
        //}
        #endregion

        #region 5.0 Deconstruction (deconstruction for tuple)
        //static void Main(string[] args)
        //{
        //    Student student = new Student();
        //    student.Name = "Steve";
        //    student.LastName = "Nguyen";
        //    var (name, lastname) = student;
        //    WriteLine($"hello mr {name} {lastname}");
        //    ReadLine();
        //}
        #endregion

        #region 6.0 Local function
        //static void Main(string[] args)
        //{
        //    Chapter1 ch1 = new Chapter1();
        //    WriteLine($"Sum: {ch1.getSum(1,2)}");
        //    ReadLine();
        //}
        #endregion

        #region 7.0 ref Return and Locals
        static void Main(string[] args)
        {
            int      a   = 10;
            int      b   = 5;
            Chapter1 ch1 = new Chapter1();
            int      val = ch1.GetLargest(a, b);

            val += 10;

            WriteLine($"{val}  {a}  {b}");

            ref int refval = ref ch1.GetLargest(ref a, ref b); // khi tra ve ad thi gan dia chi cua a vao refval nen khi refval + 10 thi a + 10
Esempio n. 2
0
        static void Main(string[] args)
        {
            //      Playing with tuples

            /***
             * int[] scores = { 17, 46, 39, 62, 81, 79, 52, 24, 49 };
             * Chapter1 ch1 = new Chapter1();
             * int threshold = 40;
             * var (average, studentCount, belowAverage) = ch1.GetAverageAndCount(scores, threshold);
             * WriteLine($"Average was {Round(average,2)} across {studentCount} students. { (average < threshold ? " Class score below average." : " Class score above average.")}");
             * ReadLine();
             */

            Chapter1 ch1 = new Chapter1();

            Student student = new Student("S20323742");

            student.Name        = "Dirk";
            student.LastName    = "Strauss";
            student.CourseCodes = new List <int> {
                203, 202, 101
            };

            var(FirstName, Surname) = student;
            //WriteLine($"The student name is {FirstName} {Surname}");

            //ch1.OutputInformation(student);

            Professor prof = new Professor();

            prof.Name            = "Reinhardt";
            prof.LastName        = "Botha";
            prof.TeachesSubjects = new List <string> {
                "Mobile Development", "Cryptography"
            };

            //ch1.OutputInformation(prof);


            string sValue = "500";

            /**
             * if (int.TryParse(sValue, out var intVal))
             * {
             *  WriteLine($"{intVal} is a valid integer");
             *  // Do something with intVal
             * }
             */

            /**
             * var (original, intVal, isInteger) = sValue.ToInt();
             * if (isInteger)
             * {
             *  WriteLine($"{original} is a valid integer");
             *  // Do something with intVal
             * }
             */

            Building bldng = ch1.GetShopfloorSpace(200, 35, 100);
            //WriteLine($"The total space for shops is {bldng.TotalShopFloorSpace} square meters");

            var oldNum = 342057239127493;
            var newNum = 342_057_239_127_493;
            var binLit = 0b1010_1100_0011_0010_0001_0000;
            //WriteLine($"oldNum = {oldNum} and newNum = {newNum} and binLit = {binLit}");

            int a   = 10;
            int b   = 20;
            int val = ch1.GetLargest(a, b);

            val += 25;
            //WriteLine($"val = {val} a = {a} b = {b}");

            ref int refVal = ref ch1.GetLargest(ref a, ref b);