Beispiel #1
0
        static void Main(string[] args)
        {
            Program tmpC   = new Program();
            int     total1 = tmpC.SumAll(1, 2);//배열 자동생성
            int     total2 = tmpC.SumAll(1, 2, 3, 4, 5);
            int     total3 = tmpC.SumAll(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            Console.WriteLine(total1);
            Console.WriteLine(total2);
            Console.WriteLine(total3);

            int[] param4 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int   total4 = tmpC.SumAll2(param4);//배열을 넣어야 함.

            Console.WriteLine(total4);

            tmpC.SelectCard(10, "Diamond");
            tmpC.SelectCard(aNumber: 12, aShape: "Diamond");
            tmpC.SelectCard(aShape: "Heart", aNumber: 12);

            tmpC.MakeCard(7);
            tmpC.MakeCard(10, "Heart");

            CSmartPhone tmpSP1 = new CSmartPhone();
            CSmartPhone tmpSP2 = new CSamsungPhone();
            CSmartPhone tmpSP3 = new CLGPhone();

            Console.WriteLine(tmpSP1.GetMarket());
            Console.WriteLine(tmpSP2.GetMarket());
            Console.WriteLine(tmpSP3.GetMarket());

            Console.WriteLine(tmpSP1.GetButtonCount());
            Console.WriteLine(tmpSP2.GetButtonCount());
            Console.WriteLine(tmpSP3.GetButtonCount());

            if (tmpSP2 is CSamsungPhone)//java에서 instance of
            {
                CSamsungPhone tmpSP4 = (CSamsungPhone)tmpSP2;
                Console.WriteLine(tmpSP4.GetButtonCount());
            }

            CLGPhone tmpSP5 = tmpSP3 as CLGPhone;//실패하면 널

            if (tmpSP5 != null)
            {
                Console.WriteLine(tmpSP5.GetButtonCount());
            }
            CSmartPhone tmpSP7 = new CSmartPhone();
            CSmartPhone tmpSP8 = new CSmartPhone(); // 초기화 안하면 error.
            CSmartPhone tmpSP9;                     // = new CSmartPhone(); //out은 초기화 안해도 됨.

            UseSmartPhone(tmpSP7);
            ChangeSmartPhone(ref tmpSP8);
            MakeSmartPhone(out tmpSP9);

            Console.WriteLine(tmpSP7.theID);
            Console.WriteLine(tmpSP8.theID);
            Console.WriteLine(tmpSP9.theID);

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Program tmpC   = new Program();
            int     total1 = tmpC.SumAll(1, 2);
            int     total2 = tmpC.SumAll(1, 2, 3, 4, 5);
            int     total3 = tmpC.SumAll(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            Console.WriteLine(total1);
            Console.WriteLine(total2);
            Console.WriteLine(total3);

            int[] param4 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int   total4 = tmpC.SumAll2(param4);

            Console.WriteLine(total4);

            tmpC.SelectCard(10, "Diamond");
            //이런식으로 매개변수를 전달할 수 있음
            tmpC.SelectCard(aNumber: 12, aShape: "Diamond");
            tmpC.SelectCard(aShape: "Heart", aNumber: 12);   //이런식으로 전달해도 오류 안남

            tmpC.MakeCard(7);
            tmpC.MakeCard(10, "Heart");
            tmpC.MakeCard(aShape: "Heart", aNumber: 10);


            CSmartPhone tmpSP1 = new CSmartPhone();
            CSmartPhone tmpSP2 = new CSamsungPhone(); //업캐스팅
            CSmartPhone tmpSP3 = new CLGPhone();      //업캐스팅


            //base 키워드 사용하여 모두 부모클래스의 GetMarket 함수 호출
            Console.WriteLine(tmpSP1.GetMarket());
            Console.WriteLine(tmpSP2.GetMarket());
            Console.WriteLine(tmpSP3.GetMarket());

            //상위클래스의 함수 호출 -> virtual 키워드를 사용하지 않았기 때문
            Console.WriteLine(tmpSP1.GetButtonCount());
            Console.WriteLine(tmpSP2.GetButtonCount());
            Console.WriteLine(tmpSP3.GetButtonCount());

            if (tmpSP2 is CSamsungPhone) // is 연산자는 형변환 가능여부 확인, 가능하면 true, 불가능 하면 false 반환
            {
                CSamsungPhone tmpSP4 = (CSamsungPhone)tmpSP2;
                Console.WriteLine(tmpSP4.GetButtonCount());
            }
            CLGPhone tmpSP5 = tmpSP3 as CLGPhone; // as는 형변환이 가능하면 형변환된 객체로 반환, 아니면 null 반환

            if (tmpSP5 != null)
            {
                Console.WriteLine(tmpSP5.GetButtonCount());
            }

            CSmartPhone tmpSP7 = new CSmartPhone();
            CSmartPhone tmpSP8 = new CSmartPhone();
            CSmartPhone tmpSP9;

            UseSmartPhone(tmpSP7);
            ChangeSmartPhone(ref tmpSP8); // ref는 밖에서 꼭 생성
            MakeSmartPhone(out tmpSP9);   // out은 안에서 꼭 생성

            Console.WriteLine(tmpSP7.theID);
            Console.WriteLine(tmpSP8.theID);
            Console.WriteLine(tmpSP9.theID);

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Program tmpC   = new Program();
            int     total1 = tmpC.SumAll(1, 2);
            int     total2 = tmpC.SumAll(1, 2, 3, 4);
            int     total3 = tmpC.SumAll(1, 2, 3, 4, 5, 6, 7);

            Console.WriteLine(total1);
            Console.WriteLine(total2);
            Console.WriteLine(total3);

            int[] param4 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int   total4 = tmpC.SumAll2(param4);

            Console.WriteLine(total4);

            tmpC.SelectCard(10, "Diamond");
            tmpC.SelectCard(aNumber: 12, aShape: "Diamond"); //순서 바뀌ㅇㅓ도 됨,
            tmpC.SelectCard(aShape: "Heart", aNumber: 12);

            tmpC.MakeCard(7);
            tmpC.MakeCard(10, "Heart");

            CSmartPhone tmpSP1 = new CSmartPhone();
            CSmartPhone tmpSP2 = new CSamsungPhone();
            CSmartPhone tmpSP3 = new CLGPhone();

            Console.WriteLine(tmpSP1.GetMarket());
            Console.WriteLine(tmpSP2.GetMarket());
            Console.WriteLine(tmpSP3.GetMarket());

            Console.WriteLine(tmpSP1.GetButtonCount()); //1
            Console.WriteLine(tmpSP2.GetButtonCount()); //1
            Console.WriteLine(tmpSP3.GetButtonCount()); //1

            if (tmpSP2 is CSamsungPhone)                //is => (JAVA):instanceOf()

            {
                CSamsungPhone tmpSP4 = (CSamsungPhone)tmpSP2;
                Console.WriteLine(tmpSP4.GetButtonCount());//3
            }

            CLGPhone tmpSP5 = tmpSP3 as CLGPhone; //자바 : dynamic_test<>() as역할.

            if (tmpSP5 != null)
            {
                Console.WriteLine(tmpSP5.GetButtonCount());
            }

            CSmartPhone tmpSP7 = new CSmartPhone();
            CSmartPhone tmpSP8 = new CSmartPhone();
            CSmartPhone tmpSP9;// = new CSmartPhone(); out은 가능!

            UseSmartPhone(tmpSP7);
            ChangeSmartPhone(ref tmpSP8); //꼭 초기화
            MakeSmartPhone(out tmpSP9);   //tmpSP9가 함수 안에서 생성

            Console.WriteLine(tmpSP7.theID);
            Console.WriteLine(tmpSP8.theID);
            Console.WriteLine(tmpSP9.theID);

            Console.ReadKey();
        }