- Joined
- 2/21/10
- Messages
- 50
- Points
- 18
Look I have 2 or 3 parameters(see the code below) and I want to make sure that Im protected against all the incoming data types (int, long,double) So I have defined a method via double types. What should I do now? Provide the same method with all the combinations of data types??? Cast them to double and invoke the original double method which exposes its implementation????
Code:
public static double[,] MAdd(double[,] matrixA, double[,] matrixB)
{
int n = matrixA.GetLength(0);
int m = matrixA.GetLength(1);
double[,] matrixS = new double[n, m];
if ((n == matrixB.GetLength(0)) && (m == matrixB.GetLength(1)))
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
matrixS[i, j] = matrixA[i, j] + matrixB[i, j];
}
} return matrixS;
}
else
Console.WriteLine("Error! Matrix dimensions must exactly match!");
return matrixS;
}