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 |