Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Chapter09/Listing09.03.ProgrammingWithARecordStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class Program
{
public static void Main()
{
(int degrees, int minutes, int seconds) = (
90, 0, 0);
(int degrees, int minutes, int seconds) = (90, 0, 0);

// The constructor is generated using positional parameters
Angle angle = new(degrees, minutes, seconds);
Expand Down
12 changes: 4 additions & 8 deletions src/Chapter09/Listing09.04.EquivalentRecordStructCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ public bool Equals(Angle other) =>
&& EqualityComparer<int>.Default.Equals(Seconds, other.Seconds)
&& EqualityComparer<string>.Default.Equals(Name, other.Name);

public void Deconstruct(
out int Degrees, out int Minutes, out int Seconds, out string? Name)
{
Degrees = this.Degrees;
Minutes = this.Minutes;
Seconds = this.Seconds;
Name = this.Name;
}
public void Deconstruct(out int Degrees, out int Minutes,
out int Seconds, out string? Name)
=> (Degrees, Minutes, Seconds, Name) =
(this.Degrees, this.Minutes, this.Seconds, this.Name);
}
#endregion INCLUDE
18 changes: 11 additions & 7 deletions src/Chapter09/Listing09.06.EquivalentRecordClassCode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_06;

#region INCLUDE
using System.Runtime.CompilerServices;
using System.Text;
Expand All @@ -12,8 +13,7 @@ public class Coordinate : IEquatable<Coordinate>
public Angle Longitude { get; init; }
public Angle Latitude { get; init; }

public Coordinate(Angle Longitude, Angle Latitude) :
base()
public Coordinate(Angle Longitude, Angle Latitude) : base()
{
this.Longitude = Longitude;
this.Latitude = Latitude;
Expand Down Expand Up @@ -42,11 +42,14 @@ protected virtual bool PrintMembers(StringBuilder builder)
return true;
}

public static bool operator !=(Coordinate? left, Coordinate? right) =>
!(left == right);
public static bool operator !=(
Coordinate? left, Coordinate? right) =>
!(left == right);

public static bool operator ==(Coordinate? left, Coordinate? right) =>
ReferenceEquals(left, right) || (left?.Equals(right) ?? false);
public static bool operator ==(
Coordinate? left, Coordinate? right) =>
ReferenceEquals(left, right) ||
(left?.Equals(right) ?? false);

public override int GetHashCode()
{
Expand All @@ -70,7 +73,8 @@ public virtual bool Equals(Coordinate? other) =>
&& EqualityComparer<Angle>.Default.Equals(
Latitude, other!.Latitude));

public void Deconstruct(out Angle Longitude, out Angle Latitude)
public void Deconstruct(
out Angle Longitude, out Angle Latitude)
{
Longitude = this.Longitude;
Latitude = this.Latitude;
Expand Down