Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Implementation of Indexer C#
- class State
- {
- //class member
- private string name;
- private string[] places = new string[3];
- //setting the properties
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public string this[int index]
- {
- get { return places[index]; }
- set { places[index] = value; }
- }
- public void DisplayAllPlaces()
- {
- Console.WriteLine("The Places of " + name + " State:");
- foreach(string place in places)
- {
- Console.WriteLine(place);
- }
- }
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- State s = new State();
- s.Name = "Bagmati";
- s[0] = "BalKumari";
- s[1] = "Kalanki";
- s[2] = "Imadol";
- s.DisplayAllPlaces();
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement