오늘의 C# 공부. 테스트 문제 , 클래스

눈폭탄에 워크샵에 두 번 빠졌더니 못따라가겠…

////Test 문제

//using System;

//namespace EX6_2
//{
//    class HelloWorld
//    {
//        public static void Main()
//        {
//            double mean = 0;

//            Mean(1, 2, 3, 4, 5, ref mean);

//            Console.WriteLine(“평균: {0}",  mean);
//        }

//        public static void Mean(double a, double b, double c, double d, double e, ref double mean)
//        {
//            mean = (a + b + c + d + e) / 5;
//        }
//    }
//}

//////Test 문제
////using System;

////namespace EX6_1
////{
////    class HelloWorld
////    {
////        static double Square(double arg)
////        {
////            arg *= arg;
////            return arg;
////        }

////        static void Main(string[] args)
////        {
////            Console.Write(“수를 입력하세요: “);
////            string input = Console.ReadLine();
////            double arg = Convert.ToDouble(input);

////            Console.WriteLine(“결과:{0}”, Square(arg));
////        }
////    }
////}

////테스트 3번
//using System;

//namespace EX6_3
//{
//    class HelloWorid
//    {
//        public static void Main()
//        {
//            int a = 3;
//            int b = 4;
//            int resultA = 0;

//            Plus(a, b, out resultA);

//            Console.WriteLine("{0} + {1} = {2}”, a, b, resultA);

//            double x = 2.4;
//            double y = 3.1;
//            double resultB = 0;

//            Plus(x, y, out resultB);

//            Console.WriteLine("{0} + {1} = {2}”, x, y, resultB);
//        }

//        public static void Plus(int a, int b, out int c)
//        {
//            c = a + b;
//        }

//        public static void Plus(double a, double b, out double c)
//        {
//            c = a + b;
//        }

//    }
//}

////클래스를 선언하고 객체를 생성하는 예제 프로그램
//using System;

//namespace BasicClass
//{
//    class Cat
//    {
//        public string Name;
//        public string Color;

//        public void Meow()
//        {
//            Console.WriteLine("{0}:야옹”,Name);
//        }
//    }

//    class MainApp
//    {
//        static void Main(string[] args)
//        {
//            Cat kitty = new Cat();
//            kitty.Color = “하얀색”;
//            kitty.Name = “키티”;
//            kitty.Meow();
//            Console.WriteLine("{0} : {1}", kitty.Name, kitty.Color);

//            Cat nero = new Cat();
//            nero.Color = “검은색”;
//            nero.Name = “네로”;
//            nero.Meow();
//            Console.WriteLine("{0} : {1}", nero.Name, nero.Color);
//        }
//    }

//}

////생성자와 소멸자

//using System;

//namespace Constructor
//{
//    class Cat
//    {

//// 생성자는 클래스 이름과 같은 메소드를 만들어 주면 되는 것이다.

//        ~Cat()
//        {
//            Console.WriteLine("{0}:잘가", Name);
//        } //소멸자는안쓴다. 그치만 알아두기만 하자. 소멸자는 생성자 있는 곳에 선언해 두기만 하면,
//        // 자동으로 프로그램이 끝난 후에 생성된 객체를 날려버린다.
//        // 그치만 GC가 있는데 굳이 수동으로 이걸 호출하는게 더 바보짓이다.

//        public Cat()
//        {
//            Name= “”;
//            Color = “”;
//        } //아무것도 안쓰면 아무것도 없는 값으로 들어가게 된다.

//        public Cat(string _Name, string _Color)
//        {
//            Name = _Name;
//            Color = _Color;
//        }// 이름을 굳이 쓰면 이름이 들어가도록 오버로딩이 되어 있다.

       
//        public string Name;
//        public string Color;

//        public void Meow()
//        {
//            Console.WriteLine("{0} : 야옹",Name);
//        }
//    }

//    class HelloWorld
//    {
//        static void Main()
//        {
//            Cat kitty = new Cat(“키티”, “하얀색”);
//            kitty.Meow();
//            Console.WriteLine("{0},{1}", kitty.Name, kitty.Color);

//            Cat nero = new Cat(“네로”, “검은색”);
//            nero.Meow();
//            Console.WriteLine("{0},{1}", nero.Name, nero.Color);
//        }
//    }

//}

////딥카피
//// 딥카피는 수동으로 만들어 줘야 한다
//using System;

//namespace DeepCopy
//{
//    class MyClass
//    {
//        public int MyField1;
//        public int MyField2;

//        public MyClass DeepCopy()
//        {
//            MyClass newCopy = new MyClass(); // 클래스를 new 시키고 초기화한다.
//            newCopy.MyField1 = this.MyField1; // 새로 만든 class 에 ‘지금 현재 있는 값’ 을 집어 넣는다.
//            newCopy.MyField2 = this.MyField2;
//            return newCopy; //그리고 그걸 리턴한다.
//        }
//    }

//    class HelloWorld
//    {
//        static void Main()
//        {
//            Console.WriteLine(“얕은 카피 : Shallow Copy”);
//            {
//                MyClass source = new MyClass();
//                source.MyField1 = 10;
//                source.MyField2 = 20;

//                MyClass target = source;
//                target.MyField2 = 30;

//                Console.WriteLine ("{0} {1}", source.MyField1, source.MyField2);
//                Console.WriteLine ("{0} {1}", target.MyField1, target.MyField2);
//            }

//            Console.WriteLine(“딥카피 : Deep Copy”);
//            {
//                MyClass source = new MyClass();
//                source.MyField1 = 10;
//                source.MyField2 = 20;

//                MyClass target = source.DeepCopy();
//                target.MyField2 = 30;
               
//                Console.WriteLine("{0} {1}",source.MyField1,source.MyField2);
//                Console.WriteLine("{0} {1}",target.MyField1, target.MyField2);
//            }
//        }
//    }
//}

////this 키워드
////자기 자신의 필드나 메소드에 접근할 때 this 키워드를 사용한다.

//using System;

//namespace This
//{
//    class Employee
//    {
//        private string Name;
//        private string Position;

//        public void SetName(string Name)
//        {
//            this.Name = Name;
//        }

//        public string GetName()
//        {
//            return Name;
//        }

//        public void SetPositon(string Position)
//        {
//            this.Position = Position;
//        }

//        public string GetPosition()
//        {
//            return this.Position;
//        }
//    }

//    class HelloWorld
//    {
//        static void Main(string[] args)
//        {
//            Employee pooh = new Employee();
//            pooh.SetName(“pooh”);
//            pooh.SetPositon(“waiter”);
//            Console.WriteLine("{0} {1}", pooh.GetName(), pooh.GetPosition());

//            Employee tigger = new Employee();
//            tigger.SetName(“tigger”);
//            tigger.SetPositon(“Cleaner”);
//            Console.WriteLine("{0} {1}", tigger.GetName(), tigger.GetPosition());
//        }
//    }
//}

Hugo로 만듦
JimmyStack 테마 사용 중