Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vangj committed Apr 22, 2023
1 parent 58c5a58 commit b4c11da
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
20 changes: 16 additions & 4 deletions app-oop/Coder/Model.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Coder.Model
{
public class Human
public class HumanClazz
{
public string FirstName { get; set; }
public string LastName { get; set; }

public Human(string firstName, string lastName)
public HumanClazz(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
Expand All @@ -18,12 +18,12 @@ public override int GetHashCode()

public override bool Equals(object? obj)
{
if (obj is null || obj.GetType() != typeof(Human))
if (obj is null || obj.GetType() != typeof(HumanClazz))
{
return false;
}

var that = (Human)obj;
var that = (HumanClazz)obj;
return this.FirstName.Equals(that.FirstName) &&
this.LastName.Equals(that.LastName);
}
Expand All @@ -34,5 +34,17 @@ public override string ToString()
}
}

public struct HumanStruct {
public string FirstName;
public string LastName;

public HumanStruct(string firstName, string lastName) {
this.FirstName = firstName;
this.LastName = lastName;
}
}

public record HumanRecord(string FirstName, string LastName);

public record Pet(string Name, string Sound);
}
33 changes: 31 additions & 2 deletions app-oop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,41 @@ internal class Program
private static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Human h1 = new Human("John", "Wick");
Human h2 = new Human("Jack", "Sparrow");
HumanClazz h1 = new HumanClazz("John", "Wick");
HumanClazz h2 = new HumanClazz("John", "Wick");
HumanClazz h3 = new HumanClazz("Jack", "Sparrow");

Console.WriteLine($"{h1}, {h1.GetHashCode()}");
Console.WriteLine($"{h2}, {h2.GetHashCode()}");
Console.WriteLine($"{h3}, {h3.GetHashCode()}");
Console.WriteLine($"{h1.Equals(h2)}");
Console.WriteLine($"{h1.Equals(h3)}");

Console.WriteLine(new string('-', 15));

HumanStruct h4 = new HumanStruct("John", "Wick");
HumanStruct h5 = new HumanStruct("John", "Wick");
HumanStruct h6 = new HumanStruct("Jack", "Sparrow");

Console.WriteLine($"{h4}, {h4.GetHashCode()}");
Console.WriteLine($"{h5}, {h5.GetHashCode()}");
Console.WriteLine($"{h6}, {h6.GetHashCode()}");
Console.WriteLine($"{h4.Equals(h5)}");
Console.WriteLine($"{h5.Equals(h6)}");

Console.WriteLine(new string('-', 15));

HumanRecord h7 = new HumanRecord("John", "Wick");
HumanRecord h8 = new HumanRecord("John", "Wick");
HumanRecord h9 = new HumanRecord("Jack", "Sparrow");

Console.WriteLine($"{h7}, {h7.GetHashCode()}");
Console.WriteLine($"{h8}, {h8.GetHashCode()}");
Console.WriteLine($"{h9}, {h9.GetHashCode()}");
Console.WriteLine($"{h7.Equals(h8)}");
Console.WriteLine($"{h7.Equals(h9)}");

Console.WriteLine(new string('-', 15));

Pet[] pets = {
new("Cat", "meow"),
Expand Down

0 comments on commit b4c11da

Please sign in to comment.