-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathListing02.09.UsingStringFormat.cs
More file actions
36 lines (29 loc) · 1.01 KB
/
Listing02.09.UsingStringFormat.cs
File metadata and controls
36 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_09;
using System;
using System.Globalization;
public class Program
{
public static void Main()
{
#region INCLUDE
// ...
const double number = 86540910.21;
string currencyText;
currencyText = $"{number}";
Console.WriteLine(currencyText);
currencyText = $"{number:C}";
Console.WriteLine(currencyText);
// Prove that string interpolation and the ToString method
// produce equivalent results with format specifiers
string toStringCurrencyText = number.ToString("C");
Console.WriteLine(
$"{currencyText == toStringCurrencyText}: " +
$"{currencyText} == {toStringCurrencyText}");
// el-GR represents the Greek locale code
toStringCurrencyText = number.ToString("C",
CultureInfo.GetCultureInfo("el-GR"));
Console.WriteLine(toStringCurrencyText);
// ...
#endregion INCLUDE
}
}