1

When including a reference to 'System.Windows.Forms.Keys' and 'Microsoft.Xna.Framework.Input.Keys' referring to the enum 'Keys' becomes ambiguous. This ambiguity is with due reason, however is there a way in Microsoft Visual Studio C# to declare a preferred reference to use by default when both references have been included?

Ant P
  • 24,820
  • 5
  • 68
  • 105
  • Possible duplicate of [Adding leading zeros using R](http://stackoverflow.com/questions/5812493/adding-leading-zeros-using-r) – Nooner Bear Nov 29 '16 at 14:20

1 Answers1

4

The problem isn't related to Visual Studio - it's the compiler that doesn't know what you mean so, no, there is no way to tell the IDE what you prefer.

You can work around this problem by creating an alias for the enum like so:

using XnaKeys = Microsoft.Xna.Framework.Input.Keys;

Then you can use your alias:

var x = XnaKeys.Add;
switch(x)
{
    ...
}

Note that you'll have to do this once per class file where the enumeration is used.

Refer to this article for more on using aliases.

Ant P
  • 24,820
  • 5
  • 68
  • 105