Apply nullability
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2020</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Day05 : IDay
|
||||
int maxSerialNumber = 0;
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
Seat seat = Seat_Parse(input);
|
||||
Seat? seat = Seat_Parse(input);
|
||||
if (seat == null) { continue; }
|
||||
int newSerialNumber = seat.GetSerialNumber();
|
||||
if (newSerialNumber > maxSerialNumber) { maxSerialNumber = newSerialNumber; }
|
||||
@@ -83,7 +83,7 @@ public class Day05 : IDay
|
||||
}
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
Seat seat = Seat_Parse(input);
|
||||
Seat? seat = Seat_Parse(input);
|
||||
if (seat == null) { continue; }
|
||||
|
||||
seats[seat.Column][seat.Row] = 'X';
|
||||
@@ -166,7 +166,7 @@ public class Day05 : IDay
|
||||
}
|
||||
}
|
||||
|
||||
private Seat Seat_Parse(string input)
|
||||
private Seat? Seat_Parse(string input)
|
||||
{
|
||||
if (input.Length != 10 ||
|
||||
input.All(c => c == 'F' || c == 'B' || c == 'L' || c == 'R') == false
|
||||
|
||||
@@ -123,25 +123,23 @@ public class Day07 : IDay
|
||||
|
||||
private class BaggageContainRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
public string BagColor { get; set; } = string.Empty;
|
||||
public int Count { get; init; }
|
||||
}
|
||||
|
||||
private class BaggageRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
public string BagColor { get; set; } = string.Empty;
|
||||
|
||||
public List<BaggageContainRule> Contain { get; init; }
|
||||
public List<BaggageContainRule> Contain { get; } = [];
|
||||
}
|
||||
|
||||
private BaggageRule BaggageRule_Parse(string input)
|
||||
{
|
||||
string[] words = input.Split(' ');
|
||||
string status = "Parse Color 1";
|
||||
BaggageRule rule = new() {
|
||||
Contain = [],
|
||||
};
|
||||
BaggageContainRule containRule = null;
|
||||
BaggageRule rule = new();
|
||||
BaggageContainRule? containRule = null;
|
||||
string color1 = string.Empty;
|
||||
|
||||
foreach (string word in words)
|
||||
@@ -180,6 +178,7 @@ public class Day07 : IDay
|
||||
status = "Parse Contain color 2";
|
||||
break;
|
||||
case "Parse Contain color 2":
|
||||
if(containRule == null) { break; }
|
||||
containRule.BagColor = string.Concat(color1, " ", word);
|
||||
rule.Contain.Add(containRule);
|
||||
status = "Parse Contain continue";
|
||||
|
||||
Reference in New Issue
Block a user