Sajmon

example of indexer

Apr 23rd, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. public int? this[int index] // indexer
  2.         {
  3.             get
  4.             {
  5.                 return dynamicArray[index];
  6.             }
  7.             set
  8.             {
  9.                 if (index > dynamicArray.Length) {
  10.  
  11.                     int?[] temp = new int?[index + 1]; // create temp array
  12.  
  13.                    
  14.                     for (int i = 0; i < dynamicArray.Length; i++) {
  15.                         temp[i] = dynamicArray[i]; // copying content of array to temp array
  16.                     }
  17.  
  18.                     dynamicArray = temp; // creating new array with new size
  19.  
  20.                     temp = null;
  21.                 }
  22.             }
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment