2009/Study 모임 B조2009. 2. 17. 11:22
inheritance(상속)
: 특정 class의 모든 멤버를 물려 받는 것을 말합니다.
  (메소드, 필드, 해당 class에 선언된 모든 부분)

[형식]
protected class 기반class
{
  // 멤버 목록
}

지정자 class 이름 :
기반 class
{
    //멤버 목록
}

[알아두어야 할 사항]
public, protected .. 의 지정자 class로 설정 해야 해당 class의 멤버들을 사용 할 수 있습니다.

sealed 의 지정자는 상속 할 수 없습니다.

상속 class 사용 예제 (winform)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InheritanceExam
{
    class initForm : Form
    {
        public initForm()
        {
            this.Location = new System.Drawing.Point(0,0);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Normal;
            this.Dock = DockStyle.None;
        }
    }

   
    class Program : initForm
    {
        static void Main(string[] args)
        {
            Application.Run(new Program());
        }
    }
}





Posted by penguindori
2009/Study 모임 B조2009. 2. 16. 00:18
class :  객체 지향의 가장 핵심이 되는 주체
(함수, 변수, 상수등 모든 것이 클래스 소속 되어야 함)

[형식]
 지정자 class 이름 : 기반 class
{
   // 멤버 목록
}
지정자 :                                              
 1. public class A {}
     외부에서 마음대로 Access 할 수 있습니다.
 2. private class A {}
     내부에서만 Access 할 수 있습니다.
 3. protected class A {}
     내부 혹은 상속 받을 때만 Access 할 수 있 
     습니다.
 4. sealed class A {}
    상속 할 수 없는 class 입니다.
 5. partial class A {}
     partial 을 사용 하고 class 이름이 같을 경우
     동일한 class로 인식 합니다.

기본 Class 사용 방법

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Study1
{

    class BTeam
    {
        Dictionary<int, string> userName;
        public Dictionary<int, string> inUser (int num, string uName)
        {
                #region Exception 처리
                if(num < 0 || num > 20)
                    Console.WriteLine("0~20 사이의 값을 입력해 주세요.");
                #endregion

                userName = new Dictionary<int, string>();
                userName.Add(num,uName);

                return userName;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            BTeam bjo = new BTeam();
            Dictionary<int, string> a = bjo.inUser(1, "AAA");

            foreach (KeyValuePair<int,string> KeyPrint in a)
            {
                Console.WriteLine(KeyPrint.Value);
            }

        }
    }
}









Posted by penguindori