Is there a way to retrieve the name of an object stored in a list?
What I want to do is to add an object name - the name of matrix in this particular case - prior to printing out properties of that matrix.
internal class Program
{
private static void Main(string[] args)
{
//Create a collection to help iterate later
List<Matrix> list_matrix = new List<Matrix>();
//Test if all overloads work as they should.
Matrix mat01 = new Matrix();
list_matrix.Add(mat01);
Matrix mat02 = new Matrix(3);
list_matrix.Add(mat02);
Matrix mat03 = new Matrix(2, 3);
list_matrix.Add(mat03);
Matrix mat04 = new Matrix(new[,] { { 1, 1, 3, }, { 4, 5, 6 } });
list_matrix.Add(mat04);
//Test if all methods work as they should.
foreach (Matrix mat in list_matrix)
{
//Invoking counter of rows & columns
//HERE IS what I need - instead of XXXX there should be mat01, mat02...
Console.WriteLine("Matrix XXXX has {0} Rows and {1} Columns", mat.countRows(), mat.countColumns());
}
}
}
In short I need here
Console.WriteLine("Matrix XXXX has {0} Rows and {1} Columns",
mat.countRows(),
mat.countColumns());
a method to write out name of that particular object - matrix.