开发者

how to use ConversionRate() function in CurrencyConvertion webservice?

I have included following webservice in my project

http://www.webservicex.net/CurrencyConvertor.asmx

There i got a function as ConversionRate() which takes parameters as follws

double Rate;
CurrencyConvertor ccs = new CurrencyConvertor();
Rate= ccs.ConversionRate(Currency.USD, Currency.INR);
lblResult.text=Rate.toString();

It works fine but, My application contains 2 textboxes where i want to manually show the conversion rates

I want to do as follows

Rate= ccs.ConversionRate(txtFromCurrency.text, txtToCurrency.text);
lblResult.text=Rate.toString();

so that application should atomatically convert rates and show in the lable

but 开发者_如何学运维 ConversionRate() takes arguments as Currency.(Name of Currency)

Is there any method to send these textbox parameters to the function?


OK, ConversionRate is an enumeration. For the sake of simplicitly I assume that your text boxes contain the tree letter acronym of the currency as defined by the web service. You can convert the text to the Currency enumeration by using the following code:

var curFrom = (Currency) Enum.Parse(typeof(Currency), txtFromCurrency.text, true);
var curTo = (Currency) Enum.Parse(typeof(Currency), txtToCurrency.text, true);

and then you can plug this values into the conversion Rate function

var rate = ccs.ConversionRate(curFrom, curTo);
lblResult.text = rate.toString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜