Avinash Vajpayee

Avinash Vajpayee

  • NA
  • 85
  • 21.8k

Indexer issue in call for in Main

Nov 8 2017 1:29 AM
How I Call this indexer in main class for differ in variable i,x,y 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace ConsoleApplication1  
  7. {  
  8. using System;  
  9. class SampleCollection  
  10. {  
  11. // Declare an array to store the data elements.  
  12. private T[] arr = new T[100];  
  13. private P[] prr = new P[100];  
  14. private U[] urr = new U[100];  
  15. // Define the indexer to allow client code to use [] notation.  
  16. public T this[int i]  
  17. {  
  18. get { return arr[i]; }  
  19. set { arr[i] = value; }  
  20. }  
  21. // Define the indexer to allow client code to use [] notation.  
  22. public P this[int x]  
  23. {  
  24. get { return prr[x]; }  
  25. set { prr[x] = value; }  
  26. }  
  27. // Define the indexer to allow client code to use [] notation.  
  28. public U this[int y]  
  29. {  
  30. get { return urr[y]; }  
  31. set { urr[y] = value; }  
  32. }  
  33. }  
  34. class Program  
  35. {  
  36. static void Main()  
  37. {  
  38. var stringCollection = new SampleCollection();  
  39. for (int i = 0; i < 200;i++ )  
  40. {  
  41. stringCollection[i] = new {"Hello, World",1,1};  
  42. Console.WriteLine(stringCollection[i]);  
  43. }  
  44. Console.ReadKey();  
  45. }  
  46. }  
  47. // The example displays the following output:  
  48. // Hello, World.  
  49. }