오늘의 C# 공부 : 계속 클래스 공부

////메소드 숨기기

//using System;

//namespace MethodHiding
//{
//    class Base
//    {
//        public void MyMethod()
//        {
//            Console.WriteLine(“Base.MyMethod()”);
//        }
//    }

//    class Derived : Base
//    {
//        public new void MyMethod() //MyMethod를 재정의하는 느낌이다. 그렇지만 오버라이딩처럼 완전히 바꾸진 않는다. new로 만든다.
//        {
//            Console.WriteLine(“Derived.MyMethod()”);
//        }
//    }

//    class MainApp
//    {
//        static void Main(string[] args)
//        {
//            Base baseobj = new Base();
//            baseobj.MyMethod();

//            Derived derivedObj = new Derived(); //derived 를 만들면
//            derivedObj.MyMethod(); // 같은 mymethod를 불러도 결과는 다시 정의된 녀석으로 나온다. 즉 ‘숨겨진’ 것이다.

//            Base baseOrDerived = new Derived();// 그치만 derived를 만든다 하더라도 그걸 base 클래스에 집어 넣으면
//            baseOrDerived.MyMethod(); // 숨겨졌던 base 클래스의 값이 나온다.
//        }
//    }
//}

////오버라이딩 봉인하기
//// 파생된 클래스에서 더 이상의 오버라이딩을 막기 위한 방법

//using System;

//class Base
//{
//    public virtual void SealMe()
//    {
//    }
//}

//class Derived : Base
//{
//    public sealed override void SealMe()
//    {       
//    }
//}

//class WantToOverride : Derived
//{
//    public override void SealMe();
//}

//class MainApp
//{
//    static void Main(string[] args)
//    { } //에러가 납니다 : 오류 2 ‘WantToOverride.SealMe()’: 상속된 ‘Derived.SealMe()’ 멤버가 sealed이므로 재정의할 수 없습니다. C:\jpcorp\ConsoleApplication1\ConsoleApplication1\HelloWorld.cs 64 26 ConsoleApplication1

//}

////중첩 클래스
//using System;
//using System.Collections.Generic;

//namespace NestedClass
//{
//    class Configuration
//    {
//        List listConfig = new List();

//        public void SetConfig(string item, string value)
//        {
//            ItemValue iv = new ItemValue();
//            iv.SetValue(this, item, value);
//        }

//        public string GetConfig(string item)
//        {
//            foreach (ItemValue iv in listConfig)
//            {
//                if (iv.GetItem() == item)
//                    return iv.GetValue();
//            }

//            return “”;
//        }

//        private class ItemValue
//        {
//            private string item;
//            private string value;

//            public void SetValue(Configuration config, string item, string value)
//            {
//                this.item = item;
//                this.value = value;
//                bool found = false;
//                for (int i = 0; i < config.listConfig.Count; i++)
//                {
//                    if (config.listConfig[i].item == item)
//                    {
//                        config.listConfig[i] = this;
//                        break;
//                    }
//                }

//                if (found == false)
//                {
//                    config.listConfig.Add(this);
//                }
//            }

//            public string GetItem()
//            { return item; }
//            public string GetValue()
//            { return value; }
//        }
//    }

//    class HelloWorld
//    {
//        static void Main(string[] args)
//        {
//            Configuration config = new Configuration();
//            config.SetConfig(“Version”, “V 4.0”);
//            config.SetConfig(“Size”, “655,324 KB”);

//            Console.WriteLine(config.GetConfig(“Version”));
//            Console.WriteLine(config.GetConfig(“Size”));

//            config.SetConfig(“Version”, “V 4.0.1”);
//            Console.WriteLine(config.GetConfig(“Version”));
//        }
//    }
//}

////분할 클래스
//using System;

//namespace PartialClass
//{
//    partial class MyClass
//    {
//        public void Method1 ()
//        {
//            Console.WriteLine (“Method1”);
//        }

//        public void Method2()
//        {
//            Console.WriteLine(“Method2”);
//        }
//    }

//    partial class MyClass
//    {
//        public void Method3()
//        {
//            Console.WriteLine(“Method3”);
//        }

//        public void Method4()
//        {
//            Console.WriteLine(“Method4”);
//        }
//    }

//    class MainApp
//    {
//        static void Main(string[] args)
//        {
//            MyClass obj = new MyClass();
//            obj.Method1();
//            obj.Method2();
//            obj.Method3();
//            obj.Method4();
//        }
//    }
//}

////구조체

//using System;

//namespace Structure
//{
//    struct Point3D
//    {
//        public int X;
//        public int Y;
//        public int Z;

//        public Point3D(int X, int Y, int Z)
//        {
//            this.X = X;
//            this.Y = Y;
//            this.Z = Z;
//        }

//        public override string ToString()
//        {
//            return string.Format("{0},{1},{2}", X, Y, Z);
//        }
//    }

//    class MainApp
//    {
//        static void Main(string[] args)
//        {
//            Point3D p3d1;
//            p3d1.X = 10;
//            p3d1.Y = 20;
//            p3d1.Z = 30;

//            Console.WriteLine(p3d1.ToString());

//            Point3D p3d2 = new Point3D(100, 200, 300);
//            Point3D p3d3 = p3d2;
//            p3d3.Z = 400;

//            Console.WriteLine(p3d2.ToString());
//            Console.WriteLine(p3d3.ToString());
//        }
//    }
//}

Hugo로 만듦
JimmyStack 테마 사용 중