cs11dotnet7/vs4win/Chapter02/Formatting/Program.cs

34 lines
903 B
C#
Raw Normal View History

2022-05-14 09:40:05 +02:00
int numberOfApples = 12;
2022-02-13 17:03:32 +01:00
decimal pricePerApple = 0.35M;
WriteLine(
2022-05-14 09:40:05 +02:00
format: "{0} apples cost {1:C}",
2022-02-13 17:03:32 +01:00
arg0: numberOfApples,
arg1: pricePerApple * numberOfApples);
string formatted = string.Format(
2022-05-14 09:40:05 +02:00
format: "{0} apples cost {1:C}",
2022-02-13 17:03:32 +01:00
arg0: numberOfApples,
arg1: pricePerApple * numberOfApples);
//WriteToFile(formatted); // writes the string into a file
2022-05-14 09:40:05 +02:00
WriteLine($"{numberOfApples} apples cost {pricePerApple * numberOfApples:C}");
2022-02-13 17:03:32 +01:00
Write("Type your first name and press ENTER: ");
string? firstName = ReadLine(); // nulls are expected
Write("Type your age and press ENTER: ");
string age = ReadLine()!; // null won't be returned
WriteLine(
$"Hello {firstName}, you look good for {age}.");
Write("Press any key combination: ");
ConsoleKeyInfo key = ReadKey();
WriteLine();
WriteLine("Key: {0}, Char: {1}, Modifiers: {2}",
arg0: key.Key,
arg1: key.KeyChar,
arg2: key.Modifiers);