1

I'm new to C# but trying to use an enum. The enum is as follows:

public enum PARAM : int { ROLL = 1, PITCH, YAW, MAGX, MAGY, MAGZ, BCA, OAT, IAS, TAS, VOLTS, AOA };

I'm using it as follows:

AhrsCom.setCommand("$out=" + PARAM.PITCH + ",10\n\r");

However, it passes the following string to setCommand(string command):

"$out=PITCH,10\n\r"

Instead of out=2,10\n\r, as I thought it would.

3
  • 1
    Cast the enum into int if you want to use it as an int Commented Feb 23, 2017 at 19:59
  • use AhrsCom.setCommand("$out=" + (int)PARAM.PITCH + ",10\n\r"); Commented Feb 23, 2017 at 20:01
  • Possible duplicate of C# numeric enum value as string Commented Feb 23, 2017 at 20:02

3 Answers 3

1

you need

AhrsCom.setCommand("$out=" + (int)PARAM.PITCH + ",10\n\r");

to say you want the number, not the string

Sign up to request clarification or add additional context in comments.

Comments

1

You can cast the enum to an int to gets it numeric value:

AhrsCom.setCommand("$out=" + (int)PARAM.PITCH + ",10\n\r");

Comments

0

You can cast this way:

AhrsCom.setCommand("$out=" + (int)PARAM.PITCH + ",10\n\r");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.