The short answer is no, you cannot do this natively.
The slightly longer answer is yes, you can implement such behavior using extension methods. You can add an extension method that would apply to all arrays like so:
public static class ArrayExtender
{
public static T GetValue<T>(this T[,] array, params int[] indices)
{
return (T)array.GetValue(indices);
}
public static void SetValue<T>(this T[,] array, T value, params int[] indices)
{
array.SetValue(value, indices);
}
public static T ExchangeValue<T>(this T[,] array, T value, params int[] indices)
{
var previousValue = GetValue(array, indices);
array.SetValue(value, indices);
return previousValue;
}
}
With that you can use:
var matrix = new int[3, 3];
matrix[0, 2] = 99;
var oldValue = matrix.GetValue(0, 2);
matrix.SetValue(100, 0, 2);
var newValue = matrix.GetValue(0, 2);
Console.WriteLine("Old Value = {0}", oldValue);
Console.WriteLine("New Value = {0}", newValue);
Output:
Old Value = 99
New Value = 100
In most cases there is an object-oriented answer to why you need this functionality and proper custom classes can be created to facilitate this. For example, I may have a chessboard that I create several classes with helper methods:
class GameBoard
{
public GamePiece GetPieceAtLocation(Point location) { ... }
}