using System; using System.Collections.Generic; using System.Text; namespace MyArray_ { class Program { static void Main(string[] args) { myArray t = new myArray(); t[0] = "mdaa"; t["ezeki"] = "forum.ge"; t[1] = "aba"; for (int i = 0; i < t.Count; i++) { Console.WriteLine(t[i]); } Console.WriteLine(t.Count); Console.WriteLine(t.intCount); Console.WriteLine(t[-23]); Console.Read(); } } public class myArray { const int Max = 25; private string[] strings; private string[] IntStr; public int Count = 0; public int intCount = 0; // Constructors public myArray() { strings = new string[Max]; IntStr = new string[Max]; } public myArray(string[] StartArray) { strings = new string[Max]; IntStr = new string[Max]; foreach (string s in StartArray) { IntStr[Count] = ""; strings[Count++] = s; } intCount = Count; } // Adds new String public void Add(string s) { if (Count < Max) { IntStr[Count] = ""; strings[Count++] = s; intCount++; } } // int ინდექსიანი public string this[int index] { get { if ((index < 0) || (index >= Count)) { return "Bad Index"; } else return strings[index]; } set { if (index == Count) Add(value); if (index < Count) strSendLast(index, value); } } //string ინდექსიანი public string this[string index] { get { return strings[findIndex(index)]; } set { if (index != "") { int k = findIndex(index); if (k == -1) // თუ ისეთი სტრინგი-ა ინდექსად რომელიც აქამდე არ ყოფილა { strings[Count] = value; IntStr[Count++] = index; } else { strings[k] = value; } } } } private int findIndex(string searchString) { for (int i = 0; i < Count; i++) { if (IntStr[i] == searchString) { return i; } } return -1; } private void strSendLast(int index, string value) { if (IntStr[index] != "") //როცა უნდა ჩავწეროთ ისეთ ინდექსზე რომელზეც უკვე წერია სტრინგ ინდექსიანი რამე მნიშვნელობა { IntStr[Count] = IntStr[index]; strings[Count++] = strings[index]; IntStr[index] = ""; strings[index] = value; intCount++; } else { strings[index] = value; } } } }