2013년 10월 31일 목요일

[닷넷4.0,C#예제]C# 인덱서 예제 소스, 인덱서란, C# indexer


[닷넷4.0,C#예제]C# 인덱서 예제 소스, 인덱서란, C# indexer
 
using System;
public class Animation
{
 private int total;           //총 애니메이션 편수
 private string[] title;      //각 볼륨당 제목
 private string distributor;  //유통사
 private string date;         //제작날짜
 private int price;           //가격
 public Animation(int total, string distributor, string date, int price)
 {
  this.total = total;
  this.title = new string[total];
  this.distributor = distributor;
  this.date = date;
  this.price = price;
 }
 //볼륨의 제목 설정
 public string this[string index]
 {
  get
  {
   switch(index)
   {
    case  "봄" : return title[0];
    case "여름" : return title[1];
    case "가을" : return title[2];
    case "겨울" : return title[3];
    default : return title[0];
   }

  
  }
  set
  {
  
    title[0] =value;
  
  }
 }

 //제작사 정보를 읽어옴
 public string getDistributor()
 {
  return distributor;
 }
 //가격 정보를 읽어옴
 public int getPrice()
 {
  return price;
 }
 //총애니메이션의 수를 알아내는 메소드
 public int getTotal()
 {
  return total;
 }
}
class AniTest
{
 static void Main()
 {
  Animation ani = new Animation(5, "한국애니","10-27-2004", 35000);
  ani["봄"] = "인어공주";
  ani["여름"] = "신데렐라";
  ani["가을"] = "백설공주";
  ani["겨울"] = "바보온달";
 
  Console.WriteLine("배급사: {0}", ani.getDistributor());
  Console.WriteLine("가격: {0}", ani.getPrice());
  Console.WriteLine("----------------------------");
  //for(int i=0; i < ani.getTotal(); i++)
  //{
   Console.WriteLine("Volume{0} : {1}", 1, ani["봄"]);
  //} 
 }
}
 

C#,ASP.NET마스터 8일 56시간   11-06
C#,ASP.NET마스터 18일 54시간   11-01
ASP.NET4.0 MVC 프로그래밍 11일 33시간   11-04
C#,ASP.NET마스터 8일 56시간   11-02
ASP.NET4.0 MVC 프로그래밍 4일 32시간   11-09




댓글 없음:

댓글 쓰기