블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 8. 12. 16:26 .Net Project/.Net 3.5 Sp1
반응형



using System;

public class 두번째인덱서
{
    public static void Main()
    {
        //1.레코드 생성
        Record r = new Record();
       
        //2.Data저장
        r.SetNum(1);
        r.SetName("홍길동");

        //3.Data출력
        Console.WriteLine(r.GetData(1)); //get메서드
        Console.WriteLine(r[1]); //정수형 메서드
        Console.WriteLine(r["Name"]); //문자형 메서드


    }

}
--------------------------------------------------------------
using System;
using System.Collections;

public class Record
{
    private int num;
    private string name;
    private Hashtable data = new Hashtable();
     
    public void SetNum(int num)
    {
        this.num = num; //1이 저장
        data["Num"] = num;
    }

    public void SetName(string name)
    {
        this.name = name; //홍길동
        data["Name"] = name;
    }

    public string GetData(int index)
    {
        if (index==0)
        {
            return this.num.ToString();
           
        }
        else
        {
            return this.name;
        }
       
    }

    public string this[int index]
    {
        get { return GetData(index); }
        set { }

    }
    public string this[string index]
    {
        get { return Convert.ToString(data[index]);}
        set { }

    }

}

반응형

'.Net Project > .Net 3.5 Sp1' 카테고리의 다른 글

63장 알고리즘(이진검색)  (0) 2009.08.12
62장 알고리즘(순차검색)  (0) 2009.08.12
60장 인덱스(Index)  (0) 2009.08.12
59장 속성(Property)  (0) 2009.08.12
58장 메서드 오버로드  (0) 2009.08.12
posted by Magic_kit