tags:

views:

144

answers:

2

Have this in a c# .net application:

string key = e.KeyCode.ToString();

in .net 1.1 key = "enter"

in .net 3.5 key = "return"

my question is why are they different?

+4  A: 

The Keys enum has identical values for Enter and Return (it also has a number of other duplicates). The framework chose a different value in ToString.

SLaks
thats it, verified here: http://msdn.microsoft.com/en-us/library/system.windows.forms.keys(VS.71).aspxif anyone has a cheat sheet that would be awesome.
dnndeveloper
A cheat sheet for what?
SLaks
showing what values are the same such as the enter and return key in the keys enum. you mentioned there are other duplicates.
dnndeveloper
Run this code: `Enum.GetNames(typeof(Keys)).GroupBy(k => Enum.Parse(typeof(Keys), k)).Where(g => g.Count() > 1)`
SLaks
sweet! - will give a try
dnndeveloper
It's actually a shame since having different enter and return can be useful
James Deville
What do you mean?
SLaks
A: 

Here are all of the duplicate names: This was generated by the following query in LINQPad:

Enum.GetNames(typeof(Keys))
    .GroupBy(k => Enum.Parse(typeof(Keys), k))
    .Where(g => g.Count() > 1)
    .Select(g => String.Join(", ", g.Select(k => k.ToString()).ToArray()))


Enter, Return
CapsLock, Capital
HangulMode, HanguelMode, KanaMode
KanjiMode, HanjaMode
IMEAccept, IMEAceept
Prior, PageUp
PageDown, Next
Snapshot, PrintScreen
OemSemicolon, Oem1
Oem2, OemQuestion
Oem3, Oemtilde
Oem4, OemOpenBrackets
OemPipe, Oem5
OemCloseBrackets, Oem6
OemQuotes, Oem7
Oem102, OemBackslash
SLaks