Yurttas/PL/OOL/CS/F/05/02/00/Indexers00.cs
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 2003
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : September 1, 2003
11 * @author : Salih Yurttas
12 *
13 * Indexers00.cs
14 */
15
16
17using System;
18
19namespace ABC
20{
21 public class Indexers00
22 {
23 private string[] Data;
24 private int K = 0;
25
26 public Indexers00(params string[] s)
27 {
28 Data = new string[4];
29 foreach(string t in s)
30 Data[K++] = t;
31 }
32
33 public void Add(string a)
34 {
35 if(K>=0 && K<Data.Length)
36 Data[K++] = a;
37 }
38
39 public string this[int i]
40 {
41 get {
42 if(i<0 || i>Data.Length)
43 {// unacceptable index
44 }
45 return Data[i];
46 }
47
48 set {
49 if(i>=0 && i<K)
50 Data[i] = value;
51 }
52 }
53
54 public int GetK()
55 {
56 return k;
57 }
58
59 public static void Main(string[] args)
60 {
61 Indexers00 ListA = new Indexers00("cat",
62 "lion");
63
64 ListA.Add("dog");
65 ListA.Add("tiger");
66
67 string t = "monkey";
68 ListA[1] = t;
69
70 int N = ListA.GetK();
71 for(int i=0; i<N; ++i)
72 Console.WriteLine("{0}", ListA[i]);
73 }
74 }
75}