Skip to content

Commit 9a2287b

Browse files
Fix warnings (#2419)
[no important files changed]
1 parent 9e52b14 commit 9a2287b

File tree

5 files changed

+39
-62
lines changed

5 files changed

+39
-62
lines changed

exercises/practice/bank-account/BankAccountTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public async Task Can_handle_concurrent_transactions()
162162
account.Deposit(1m);
163163
account.Withdraw(1m);
164164
}
165-
}));
165+
}, TestContext.Current.CancellationToken));
166166
await Task.WhenAll(tasks.ToArray());
167167
}
168168
Assert.Equal(0m, account.Balance);

exercises/practice/ledger/.meta/Example.cs

+32-54
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,50 @@
11
using System.Globalization;
22

3-
public class LedgerEntry
4-
{
5-
public LedgerEntry(DateTime date, string description, decimal change)
6-
{
7-
Date = date;
8-
Description = description;
9-
Change = change;
10-
}
11-
12-
public DateTime Date { get; }
13-
public string Description { get; }
14-
public decimal Change { get; }
15-
}
3+
public record LedgerEntry(DateTime Date, string Description, decimal Change);
164

175
public static class Ledger
186
{
197
private const int TruncateLength = 25;
208
private const string TruncateSuffix = "...";
219

2210
public static LedgerEntry CreateEntry(string date, string description, int change) =>
23-
new LedgerEntry(ParseDate(date), description, ParseChange(change));
11+
new(ParseDate(date), description, ParseChange(change));
2412

2513
private static DateTime ParseDate(string date) => DateTime.Parse(date, System.Globalization.CultureInfo.InvariantCulture);
2614

2715
private static decimal ParseChange(int change) => change / 100.0m;
2816

29-
private static CultureInfo CultureInfo(string locale)
30-
{
31-
switch (locale)
17+
private static CultureInfo CultureInfo(string locale) =>
18+
locale switch
3219
{
33-
case "en-US": return new CultureInfo("en-US", false);
34-
case "nl-NL": return new CultureInfo("nl-NL", false);
35-
default: throw new ArgumentException("Invalid locale");
36-
}
37-
}
20+
"en-US" => new CultureInfo("en-US", false),
21+
"nl-NL" => new CultureInfo("nl-NL", false),
22+
_ => throw new ArgumentException("Invalid locale")
23+
};
3824

39-
private static string CurrencySymbol(string currency)
40-
{
41-
switch (currency)
25+
private static string CurrencySymbol(string currency) =>
26+
currency switch
4227
{
43-
case "USD": return "$";
44-
case "EUR": return "€";
45-
default: throw new ArgumentException("Invalid currency");
46-
}
47-
}
28+
"USD" => "$",
29+
"EUR" => "€",
30+
_ => throw new ArgumentException("Invalid currency")
31+
};
4832

49-
private static int CurrencyNegativePattern(string locale)
50-
{
51-
switch (locale)
33+
private static int CurrencyNegativePattern(string locale) =>
34+
locale switch
5235
{
53-
case "en-US": return 0;
54-
case "nl-NL": return 12;
55-
default: throw new ArgumentException("Invalid locale");
56-
}
57-
}
36+
"en-US" => 0,
37+
"nl-NL" => 12,
38+
_ => throw new ArgumentException("Invalid locale")
39+
};
5840

59-
private static string ShortDateFormat(string locale)
60-
{
61-
switch (locale)
41+
private static string ShortDateFormat(string locale) =>
42+
locale switch
6243
{
63-
case "en-US": return "MM/dd/yyyy";
64-
case "nl-NL": return "dd/MM/yyyy";
65-
default: throw new ArgumentException("Invalid locale");
66-
}
67-
}
44+
"en-US" => "MM/dd/yyyy",
45+
"nl-NL" => "dd/MM/yyyy",
46+
_ => throw new ArgumentException("Invalid locale")
47+
};
6848

6949
private static CultureInfo getCulture(string currency, string locale)
7050
{
@@ -75,15 +55,13 @@ private static CultureInfo getCulture(string currency, string locale)
7555
return culture;
7656
}
7757

78-
private static string FormatHeader(CultureInfo culture)
79-
{
80-
switch (culture.Name)
58+
private static string FormatHeader(CultureInfo culture) =>
59+
culture.Name switch
8160
{
82-
case "en-US": return "Date | Description | Change ";
83-
case "nl-NL": return "Datum | Omschrijving | Verandering ";
84-
default: throw new ArgumentException("Invalid locale");
85-
}
86-
}
61+
"en-US" => "Date | Description | Change ",
62+
"nl-NL" => "Datum | Omschrijving | Verandering ",
63+
_ => throw new ArgumentException("Invalid locale")
64+
};
8765

8866
private static string FormatDate(IFormatProvider culture, DateTime date) => date.ToString("d", culture);
8967

exercises/practice/ledger/Ledger.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public static LedgerEntry CreateEntry(string date, string desc, int chng)
2323

2424
private static CultureInfo CreateCulture(string cur, string loc)
2525
{
26-
string curSymb = null;
26+
string? curSymb = null;
2727
int curNeg = 0;
28-
string datPat = null;
28+
string? datPat = null;
2929

3030
if (cur != "USD" && cur != "EUR")
3131
{
@@ -70,9 +70,9 @@ private static CultureInfo CreateCulture(string cur, string loc)
7070
}
7171

7272
var culture = new CultureInfo(loc, false);
73-
culture.NumberFormat.CurrencySymbol = curSymb;
73+
culture.NumberFormat.CurrencySymbol = curSymb!;
7474
culture.NumberFormat.CurrencyNegativePattern = curNeg;
75-
culture.DateTimeFormat.ShortDatePattern = datPat;
75+
culture.DateTimeFormat.ShortDatePattern = datPat!;
7676
return culture;
7777
}
7878

exercises/practice/markdown/.meta/Example.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public static class Markdown
55
private static string OpeningTag(string tag) => $"<{tag}>";
66
private static string ClosingTag(string tag) => $"</{tag}>";
77
private static string WrapInTag(this string text, string tag) => $"{OpeningTag(tag)}{text}{ClosingTag(tag)}";
8-
private static bool StartsWithTag(this string text, string tag) => text.StartsWith(OpeningTag(tag));
98

109
private const string HeaderMarkdown = "#";
1110
private const string BoldMarkdown = "__";

exercises/practice/markdown/Markdown.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static string ParseText(string markdown, bool list)
3131
}
3232
}
3333

34-
private static string ParseHeader(string markdown, bool list, out bool inListAfter)
34+
private static string? ParseHeader(string markdown, bool list, out bool inListAfter)
3535
{
3636
var count = 0;
3737

@@ -68,7 +68,7 @@ private static string ParseHeader(string markdown, bool list, out bool inListAft
6868
}
6969
}
7070

71-
private static string ParseLineItem(string markdown, bool list, out bool inListAfter)
71+
private static string? ParseLineItem(string markdown, bool list, out bool inListAfter)
7272
{
7373
if (markdown.StartsWith("*"))
7474
{

0 commit comments

Comments
 (0)