2015-11-08 59 views

回答

6

什麼你要找的是一個indexer

public class Matrix 
{ 
    public double this[int i, int j] 
    { 
     get 
     { 
      return internalStorage[i, j]; 
     } 
     set 
     { 
      internalStorage[i, j] = value; 
     } 
    } 
} 

你消耗它是這樣的:

var matrix = new Matrix(); 
if (matrix[i, j] > 3.0) 
{ 
    // double at index i, j is bigger than 3.0 
} 

matrix[i, j] = 5.0;