Re: Converting enum Keys value to string



For enum to int conversion use a cast:

int i = (int)Keys.F10;
Keys k = (Keys)i;

For enum to string conversion:

string s = Keys.F10.ToString();
Keys k = (Keys)Enum.Parse(typeof(Keys), s);


Rob.

"Ahmed" <ahmedbm@xxxxxxxxx> wrote in message
news:1113467832.844421.149470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I am saving the enum value of specific keys to an xml file which i then
> need to get the string representation. I believe KeysConverter is there
> for that but i have trouble using it for my purpose.
> i want to give it a value and have it spit out its Keys equivilancy for
> example.
>
> 121 -> Keys.F10
>
> I am not sure if i am playing with the right function or not but any
> advise or suggestions would be appreciated :)
>


.



Relevant Pages

  • Re: Nugget - Using control references
    ... until someone decides they want to save a 3D array. ... If the users are likely to add elements to the middle of the enum, you should save and load by the enum text. ... What you can try is this - save both the string and the number. ... Unused keys are not deleted.  When the number of elements in an array is reduced, the key entries still exist in the file. ...
    (comp.lang.labview)
  • Re: Compiling AWK
    ... the term "nil" is used to mean an uninitialized ... results in the length of the string or the number of entries in the table. ... and size arguments specify the least significant bit and size of the field. ... The two table arguments are treated as sets: The keys represent the strings ...
    (comp.lang.awk)
  • Re: Help With PyParsing of output from win32pdhutil.ShowAllProcesses()
    ... None to a string). ... Still have an urge to parse with pyparsing? ... pyparsing Dict class. ... keys from the parsed data, so it looks like you are already thinking ...
    (comp.lang.python)
  • Re: Merging hashes using both symbols and strings as keys
    ... default values for my class) and the other using strings as keys ... (taken from the params hash). ... the string, ... # the returned hash will also be extended by SymbolizeKeys ...
    (comp.lang.ruby)
  • Re: Behaviour of enumerated types
    ... >> keys to other ordered info? ... If you want sequence numbers, ... the enum object itself can be used directly as an iterable. ... >> To me the int correspondence is as expectable and natural as ...
    (comp.lang.python)