0

EDIT: I've been working with C# for Two days, I'm web developer and I come from PHP, I would need some detail explanation

I'm consuming a Currency convertor Web service. The web service namespace contain an enum structure with the currencies:

public enum Currency {
    /// <remarks/>
    AFA,
    /// <remarks/>
    ALL,
    /// <remarks/>
    DZD,
    /// <remarks/>
    ARS,
    /// <remarks/>
    AWG,
    /// <remarks/>
    AUD,
    /// <remarks/>
    BSD,
    /// <remarks/>
    BHD
    //... AND SO ON
}

The method I use to get the Conversion Rate is (with example):

// ---
// --- Variable type is the enum
// ---
ConvertorReference.Currency from;
ConvertorReference.Currency to;

ConvertorReference.CurrencyConvertorSoapClient service = new ConvertorReference.CurrencyConvertorSoapClient();

// --
// -- Here I asign one of the enum keys
// --
from = ConvertorReference.Currency.USD;
to = ConvertorReference.Currency.COP;


rate = service.ConversionRate(from, to);

Console.Write("1 USD is $" + rate + " Colombia Pesos");
//Outputs: 1 USD is $2380.88 Colombian Pesos

I would like to ask the user for a string, where he can insert for example "USD" or "COP".

After receiving that string I want to know if it is possible to use something like.

curr = Console.ReadLine("Insert the currency you want to perform the operation: ");

Now the variable curr would be something like "USD";

Can I do something like this to get the same result?:

from = ConvertorReference.Currency.curr;
JuanBonnett
  • 776
  • 3
  • 8
  • 26
  • If I've misread your question, and the above link doesn't ask/answer the same thing you're asking, can you explain more the difference of your question? – hatchet - done with SOverflow Feb 07 '15 at 17:00
  • I don't understand some C# code they put there. I'm new to C#... I would need comments so I can know what's happening. I apologize – JuanBonnett Feb 07 '15 at 17:04
  • 1
    The simple answer is use Enum.TryParse. For example, `Currency curr; if (Enum.TryParse("AFA", out curr)) { //success } else { //failed to convert};`. See https://msdn.microsoft.com/en-us/library/dd783499%28v=vs.110%29.aspx – hatchet - done with SOverflow Feb 07 '15 at 17:11

0 Answers0