3

I have the following code

Call.Direction CallDir = details.dir; 

and the output is either In or out.

my question how can I convert the output to be as follow:

  • if CallDir value is In ===> display 0
  • if CallDir value is Out ===> display 1
2
  • What's Call.Direction; an enum? If so, please show its definition. Commented Nov 17, 2013 at 3:05
  • Yes it is an enum, it is used for the direction of a call Commented Nov 17, 2013 at 3:07

2 Answers 2

3

Okay, so if you wanted to return a different value based on the enum, just do this:

return CallDir == Call.Direction.In ? 0 : 1;

However, if what you're saying is details.dir is a string of In or Out and you need to get that into an enum, then do this:

Call.Direction CallDir;
if (!enum.TryParse<Call.Direction>(details.dir, out CallDir))
{
    // set it to some default value because it failed
}
Sign up to request clarification or add additional context in comments.

Comments

2

In addition to what Michael said, if your enum is defined with the appropriate values, you can simply cast it to an int.

enum CallDirection { In = 0, Out = 1 }

var dir = CallDirection.In;

Console.Write((int)dir); // "0"

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.