0

I have an application where I get an id from the user, then "Voicetrading"+id matches one of the values in my Enum called SipUsernames. What i want to do is to get the value that matches "Voicetrading"+id and return it. Is there any way by doing it passing reference type like SipUsernames.&voicetrading.ToString() ?

Code example:

    foreach(var EnumCountry in Enum.GetValues(typeof(SipUsernames)))
       {
           string voicetrading = "Voicetrading"+id;
           if (voicetrading.Equals(EnumCountry.ToString()))
           {
               return SipUsernames.&voicetrading.ToString();                               
           }
       }

Ps. I know SipUsernames.&voicetrading is something stupid and doesn't work, but i didn't know how to express what i mean in another way.

esmehsnj
  • 162
  • 2
  • 17
  • https://stackoverflow.com/help/mcve – mjwills Nov 28 '17 at 02:03
  • Isn't in your example `SipUsernames.&voicetrading.ToString(); ` going to be just equal `voicetrading` because that is already a string? – zaitsman Nov 28 '17 at 02:05
  • @zaitsman yes they are, that is true, but my intention is to retrieve the value from the Enum – esmehsnj Nov 28 '17 at 02:09
  • Your options are to return: EnumCountry (returns the enum), EnumCountry.ToString(), or to return the underlying number of the enum: (int) EnumCountry – Tim Nov 28 '17 at 03:00

0 Answers0