Photo and Albumb Using Properties and Indexers

Pranat
0
Lamp

 using System;

class Photo

{

 private string tittle;

 public Photo(string tittle)

 {

 this.tittle = tittle;

 }

 public string Tittle

 {

 get

{

 return this.tittle;

 }

 }

}

class Albumb

{

 private string[] albumb;

 int count = 0;

 //Photo p = new Photo();

 public Albumb(int size)

 {

 albumb = new string[size];

 }

 public string this[int i]

 {

 get

 {

 return albumb[i];

 }

 }

 public int this[string str]

 {

 get

 {

 //foreach(string i in albumb)

 //{

 //albumb[count] = i;

 //}

 return Array.IndexOf(albumb, str);

 }

 }

 public void AddPhoto(String p)

 {

 albumb[count] = p;

 count++;

 }

}

class MainTest

{

 public static void Main()

 {

 Photo p1 = new Photo("Pramod");

 Photo p2 = new Photo("Dangu");

 Console.WriteLine(p1.Tittle);

 Console.WriteLine(p2.Tittle);

Albumb albumb = new Albumb(10);

 //----------------------------------------------------------

 string str1 = p1.Tittle;

 albumb.AddPhoto(str1);

 string str2 = p2.Tittle;

 albumb.AddPhoto(str2);

 //---------------------------------------------------------

 Console.WriteLine(albumb[0]);

 Console.WriteLine(albumb["Pramod"]);

 Console.WriteLine(albumb[1]);

 Console.WriteLine(albumb["Dangu1"]);

 }

}



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !