I want to write extension methods for converting a vector and matrix into string. I did this in the following way.
For Vector
public static string GetString<T>(this T[] SourceMatrix, string ColumnDelimiter = " ")
{
try
{
string result = "";
for (int i = 0; i < SourceMatrix.GetLength(0); i++)
result += SourceMatrix[i] + ColumnDelimiter;
return result;
}
catch (Exception ee) { return null; }
}
For Matrix
public static string GetString<T>(this T[][] SourceMatrix, string ColumnDelimiter = " ", string RowDelimiter = "\n")
{
try
{
string result = "";
for (int i = 0; i < SourceMatrix.GetLength(0); i++)
{
for (int j = 0; j < SourceMatrix[i].GetLength(0); j++)
result += SourceMatrix[i][j] + "" + ColumnDelimiter;
result += "" + RowDelimiter;
}
return result;
}
catch (Exception ee) { return null; }
}
Now i am using following code which causes ambiguity.
List<double[]> Patterns= GetPatterns();
Patterns.ToArray().GetString();
Error
Error 5 The call is ambiguous between the following methods or properties:
'MatrixMathLib.MatrixMath.GetString<double[]>(double[][], string)' and
'MatrixMathLib.MatrixMath.GetString<double>(double[][], string, string)'
Can anyone suggest me to write these extension methods correctly.
Thanks in advance.
string.Join(<delimiter>,<array>)
) to convert an array to string – CroteauString.Join
is not a extension method, it is a static method ofstring
class. – TheaterintheroundList<double[]>
and usingToArray()
extension which will returndouble[][]
, any way in my problem i need jagged array as each row(pattern) can have different no.of values. – Hanafee