コード例 #1
0
        static void Main(string[] args)
        {
            StudentList student1 = new StudentList();

            student1.name       = "Yakup";
            student1.surname    = "ILBEY";
            student1.age        = 21;
            student1.schoolName = "Kocaeli University";


            StudentList student2 = new StudentList();

            student2.name       = "Görken";
            student2.surname    = "IZMIR";
            student2.age        = 20;
            student2.schoolName = "Kocaeli University";


            StudentList student3 = new StudentList();

            student3.name       = "Fatih";
            student3.surname    = "KAPLAMA";
            student3.age        = 24;
            student3.schoolName = "Bilkent University";


            StudentList student4 = new StudentList();

            student4.name       = "AkiF";
            student4.surname    = "ERGİN";
            student4.age        = 21;
            student4.schoolName = "Fırat University";



            StudentList[] studentLists = new StudentList[] { student1, student2, student3, student4 };


            foreach (var student in studentLists)
            {
                Console.WriteLine("Adı Soyadı: " + student.name + " " + student.surname + "\nYaşı: " + student.age + "\nOkulu: " + student.schoolName + "\n---------------------------------\n");
            }
        }
コード例 #2
0
        static void Main(String[] args)
        {
            var calc = new Calculator();

            int a = 5;
            int b = 10;

            // C# ref
            calc.Double(a, ref b);                  // b = pass by refence : ref
                                                    // a = pass by value

            Console.WriteLine("a = {0}, b = {1}", a, b);

            // C# out  but, 변수안에 값이 있으면 실행이 안됨 그럴때엔 out이 아닌 ref
            //int sum;
            //double avg;
            //calc.GetSumAndAvg(5, 15, out sum, out avg);

            //Console.WriteLine("sum = {0}, avg = {1}",sum,avg);

            // C# 7.0
            //calc.GetSumAndAvg(5, 15, out int sum, out double avg);      // 여기서 선언가능
            //calc.GetSumAndAvg(5, 15, out var sum, out var avg);         // 프로토타입으로 파라미터를 보고 자료형 결정
            //calc.GetSumAndAvg(5, 15, out var sum, out _);

            // C# params : 가변 파라미터
            //int s = calc.Sum(1);
            //s = calc.Sum(1, 2);
            //s = calc.Sum(1, 2, 3, 4, 5);
            //s = calc.Sum();

            // Named Parameter, optional Parameter
            var st = new StudentList();

            st.AddStudent("Tim", "111-2222", 10);
            st.AddStudent("Tim", "111-2222");                           // optional parameter
            st.AddStudent(name: "Tim", age: 10, phone: "111-2222");     // named parameter
        }