0

I am looking to output the variable name e.g "RedTrait" and NOT its value e.g. 40 into a label.

        var numbers = new[] { RedTrait, BlueTrait, GreenTrait, Yellow };

        string FirstTrait;
        double dFirstTrait;
        dFirstTrait = numbers.Max();
        FirstTrait = dFirstTrait.ToString();

        lblFirst.Text = FirstTrait;

        string SecondTrait;
        double dSecondTrait = numbers.OrderBy(num => num).Reverse().ElementAt(1);
        SecondTrait = dSecondTrait.ToString();

        lblSecond.Text = SecondTrait;

this is my current code, the code not shown above just produces the value of my variables in the array. Each variable holds a value. When run the labels correctly display the value but not the variable name. E.g "RedTrait" rather than "40"

  • Possible duplicate: http://stackoverflow.com/questions/716399/c-sharp-how-do-you-get-a-variables-name-as-it-was-physically-typed-in-its-dec – DonBoitnott Feb 12 '14 at 19:42

1 Answers1

0

If I understand your question correctly... you want to do something like this:

lblSecondTrait.Text = SecondTrait.VariableName; // not a real value

but at this point, your basically hard-coding your value. SecondTrait will always be SecondTrait, so you might as well write

lblSecondTrait.Text = "Second Trait";

Why would this not work?

dckuehn
  • 2,427
  • 3
  • 27
  • 37