Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A
- {
- private List<int> values = new List<int>();
- public int GetValue(int index)
- {
- return values[index];
- }
- }
- public int this[int key]
- {
- get
- {
- return GetValue(key);
- }
- set
- {
- SetValue(key,value);
- }
- }
- class SampleCollection<T>
- {
- private T[] arr = new T[100];
- public T this[int i]
- {
- get
- {
- return arr[i];
- }
- set
- {
- arr[i] = value;
- }
- }
- }
- // This class shows how client code uses the indexer
- class Program
- {
- static void Main(string[] args)
- {
- SampleCollection<string> stringCollection =
- new SampleCollection<string>();
- stringCollection[0] = "Hello, World";
- System.Console.WriteLine(stringCollection[0]);
- }
- }
- public int this[int index]
- {
- get
- {
- return GetValue(index);
- }
- }
- public int this[int index]
- {
- get
- {
- return GetValue(index);
- }
- set
- {
- SetValue(index, value);
- }
- }
- public int this[string index]
- ...
- public int this[int index]
- {
- return values[index];
- }
Add Comment
Please, Sign In to add comment