0

here`s a simple question:

I have something like this

       Youtube youtubeChannel = new Youtube();

       Console.WriteLine("youtubeChannel");

Instead hardcoding youtubeChannel in console, i want to get reference name as string and print it in console. Something like:

       Console.WriteLine(youtubeChannel.ToString());

And get result -> "youtubeChannel" in console.

  • 3
    Check this out: http://stackoverflow.com/questions/9801624/get-name-of-a-variable-or-parameter – Dunken Apr 02 '14 at 20:40
  • possible duplicate of [How to get variable name using reflection?](http://stackoverflow.com/questions/2566101/how-to-get-variable-name-using-reflection) – LakshmiNarayanan Apr 02 '14 at 21:09

1 Answers1

1

You can check how it was done here and take note of the pitfalls too..

Community
  • 1
  • 1
syntax error
  • 149
  • 1
  • 5
  • 2
    If you find this is a duplicate question, then please flag it as such. The link will appear automatically. – CodeCaster Apr 02 '14 at 20:46