0

I have several two dimensional arrays with names like

object[,] s1l2
object[,] s3l4
object[,] s4l2
object[,] s9l4

etc.

In another class, I have a method that must get that array name as string variable, like:

methodName(string arrayName);

I tried to s9l4.ToString(); but obviously that return - System.Object[,]

So, question is — how can i get object[,] s9l4 as string — "s9l4"

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Blind RD
  • 9
  • 1

1 Answers1

1

I feel like I have to not answer your explicit question, but instead challenge the premise and ask you to revise your understanding of what objects are vs. what variables are. Take this snippet:

object[,] s3l4 = new object[0,0];
object[,] s4l2 = s3l4;

In this case, you have one object - the initialized array in the first line - but two variables that both point to it. In this case, what would be the "name" of that array? s3l4 or s4l2? The answer is "neither", because both of these strings refer to a variable name inside a method, a local name that refers to the object in memory. After compiling, these names usually go away - they're used by you and your code to refer to it, but the CPU has no need for this name, it just cares about memory addresses.

So I'm guessing, if you need those strings, that you're somehow conflating between a specific object in memory, and the ad-hoc handle used to refer to it, which is probably not your intention.

Avner Shahar-Kashtan
  • 14,492
  • 3
  • 37
  • 63