Which code should you use?

You are a Web developer for Contonso. You are creating an online inventory Web site to be used by employees in Germany and the United States.
When a user selects a specific item from the inventory, the site needs to display the cost of the item in both United States currency and German currency.
The cost must be displayed appropriately for each locale.
You want to create a function to perform this task.
Which code should you use?

You are a Web developer for Contonso. You are creating an online inventory Web site to be used by employees in Germany and the United States.
When a user selects a specific item from the inventory, the site needs to display the cost of the item in both United States currency and German currency.
The cost must be displayed appropriately for each locale.
You want to create a function to perform this task.
Which code should you use?

A.
private string CKGetDisplayValue(double value,string inputRegion)
{
string display:
RegionInfo region;
region = new RegionInfo(inputRegion);
display = value.ToString(�C�);
display += region.CurrencySymbol;
return display;
}

B.
private string CKGetDisplayValue(double value,string inputCulture)
{
string display;
NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
display = value.ToString(�C�, LocalFormat);
return display;
}

C.
private string CKGetDisplayValue(double value,string inputRegion)
{
string display;
RegionInfo region;
region = new RegionInfo(inputRegion);
display = value.ToString(�C�);
display += region.ISOCurrencySymbol;
return display;
}

D.
private string CKGetDisplayValue(double value, string inputCulture)
{
string display;
CultureInfo culture;
culture = new CultureInfo(inputCulture);
display = value.ToString(�C�, culture);
return display;
}

Explanation:
We create a new CultureInfo object based on the inputCulture parameter. We then produce the
result with �C� constant, representing the current culture, and the new CultureInfo object: display =
value.ToString(�C�, culture)
Note: The CultureInfo Class contains culture-specific information, such as the language, country/region,
calendar, and cultural conventions associated with a specific culture. This class also provides the information
required for performing culture-specific operations, such as casing, formatting dates and numbers, and
comparing strings.
Incorrect Answers
B: The NumberFormatInfo class defines how currency, decimal separators, and other numeric symbols are
formatted and displayed based on culture. However, we should create a CultureInfo object, not a
NumberFormatInfo object).
A, C: We should use the CultureInfo class not the RegionInfo class.
Note: In contrast to CultureInfo, RegionInfo does not represent preferences of the user and does not
depend on the user�s language or culture.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


seenagape

seenagape

I agree with the answer. D