Advertisement
Ishu_15hu

Indexer C#

Nov 5th, 2020
1,825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. public class addd
  3. {
  4.     public string[] girlfriend = new string[3];
  5.    
  6.     public string this[int i]  
  7.             {  
  8.                 get  
  9.                 {  
  10.                     return girlfriend[i];  
  11.                 }  
  12.                 set  
  13.                 {  
  14.                     girlfriend[i] = value;  
  15.                 }  
  16.             }  
  17. }
  18.  
  19. public class Program
  20. {
  21.     public static void Main()
  22.     {
  23.         addd obj = new addd();
  24.         obj[0] = "Riya the Kid";
  25.         obj[1] = "Riya the KID";
  26.         obj[2] = "Riya the kid";
  27.        
  28.         for(int i=0;i<3;i++) {
  29.             Console.WriteLine(obj[i]);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement