Is it possible to get the name of a variable that points to a reference? Take the example below:
private void FillArray(int[] array, int count)
{
array = new int[count];
for (int i = 0; i < array.Length; i++)
{
array[i] = i;
}
Debug.WriteLine("Array {0} is now filled up with {1} values", array.Name, count);
}
There is no property Name for the array that is going to be used in the above method. I know that a workaround would be adding another parameter as string and assign the name to it, but how to do this programitically? Also I know I can make my own implementation, but I am interested to know the answer to this particular question!
[CallerMemberName]in C# 5, but that's only going to give you the method or property name of the caller, and is "filled in" by the compiler, not provided by the runtime.